Client¶
-
class inori.Client(base_uri, auth=
None
)¶ Base for an API instance.
Client takes a string to use as the base for the API.
Route objects are built by calling Client.add_route() with a string template. Route objects then become attributes of the Client.
Example
>>> client = Client('http://my.service/api/v777') >>> client.add_route('fruits/oranges')
>>> result_1 = client.fruits.get() >>> result_2 = client.fruits.oranges.get()
Routes can use any standard HTTP verb, or make a request directly:
Example
>>> client = Client('http://my.service/api/v777') >>> client.add_route('fruits/oranges')
>>> result = client.fruits.request('GET')
Routes requiring attributes are declared using a template, then provided by calling the Route.
Example
>>> client = Client('http://my.service/api/v777') >>> client.add_route('fruits') >>> client.add_route('fruits/${fruitId}')
>>> response = client.fruits(fruitId='8').get()
The string template doesn’t need to be provided in pieces, every piece will be turned into an attribute:
Example
>>> client = Client('http://my.service/api/v777') >>> client.add_route('fruits/${fruitId}')
>>> response = client.fruits(fruitId='5').get()
Python keywords get an underscore prefix.
Example
>>> client = Client('http://my.service/api/v777') >>> client.add_route('import/${importId}')
>>> response = client._import(importId='5').get()
- headers¶
Dictionary containing all Client-level headers.
- request_kwargs¶
Dictionary of any arguments to send with every request. Applies to all registered Routes.
- logger¶
Unique logger instance for each Client instance.
-
add_route(path, trailing_slash=
False
)¶ Take a path string and create Route objects from it.
Route objects are automatically set as attributes of the Client instance.