Api¶
-
class
repose.api.Api(**options)¶ A top-level API representation
Initialising an
Apiinstance is a necessary step as doing so will furnish all registered Resources (and their Managers) with access to the API backend.For example:
my_api = Api(base_url='http://example.com/api/v1') my_api.register_resource(User) my_api.register_resource(Comment) my_api.register_resource(Page)
The same can be achieved by implementing a child class. This also gives the additional flexibility of being able to add more complex logic by overriding existing methods. For example:
class MyApi(Api): # Alternative way to provide base_url and resources base_url = '/api/v1' resources = [User, Comment, Page] # Additionally, customise the base URL generation def get_base_url(self): return 'http://{host}/api/{account}'.format( host=self.host, account=self.account, ) my_api = MyApi(host='myhost.com', account='my-account')
-
base_url¶ str
The fully-qualified base URL to the the API. (Eg:
"http://example.com")
-
backend_class¶ -
The class to instantiate for use as the Api Backend (default:
ApiBackend).
-
resources¶ list[Resource]
Resourceclasses to register with the API. Can also be registered usingregister_resource().
-
client_class¶ The client class to instantiate. Should be either
Clientor a subclass thereof.
-
__init__(**options)¶ Initialise the Api
Pass options in to customise instance variables. For example:
my_api = Api(base_url='http://example.com/api/v1')
Parameters: - base_url (str) – The fully-qualified base URL to the the API.
(Eg:
"http://example.com") - backend_class (
ApiBackend) – The class to instantiate for use as the Api Backend (default:ApiBackend). - resources (list[Resource]) –
Resourceclasses to register with the API. Can also be registered usingregister_resource(). - **options – All options specified will will become available as instance variables.
- base_url (str) – The fully-qualified base URL to the the API.
(Eg:
-
backend_class alias of
ApiBackend
-