ApiBackend

class repose.apibackend.ApiBackend(base_url)

Default backend implementation providing HTTP access to the remote API

This can be extended and passed into your Api instance at instantiation time. This can be useful if you need to customise how requests are made, or how responses are parsed.

__init__(base_url)

Instantiate this class

Parameters:base_url (str) – The fully-qualified base URL to the the API. (Eg: "http://example.com").
delete(endpoint, json)

Perform a HTTP DELETE request for the specified endpoint

Parameters:json (dict) – The JSON body to post with the request
Returns:Typically a python list, dictionary, or None
Return type:object
get(endpoint, params=None)

Perform a HTTP GET request for the specified endpoint

Parameters:params (dict) – Dictionary of URL params
Returns:Typically a python list or dictionary
Return type:object
make_url(endpoint)

Construct the fully qualified URL for the given endpoint.

For example:

>>> my_backend = ApiBackend(base_url="http://example.com/api")
>>> my_backend.make_url("/user/1")
"http://example.com/api/user/1"
Parameters:endpoint (str) – The API endpoint (Eg: "/user/1").
Returns:The fully qualified URL
Return type:str
parse_response(response)

Parse a response into a Python structure

Parameters:response (requests.Response) – A Response object, unless otherwise provided by the get()
Returns:Typically a python list or dictionary
Return type:object
post(endpoint, json)

Perform a HTTP POST request for the specified endpoint

Parameters:json (dict) – The JSON body to post with the request
Returns:Typically a python list, dictionary, or None
Return type:object
put(endpoint, json)

Perform a HTTP PUT request for the specified endpoint

Parameters:json (dict) – The JSON body to post with the request
Returns:Typically a python list, dictionary, or None
Return type:object