This section covers API documentation for all classes and functions related to constructing REST API resources. For more information on resources in TBone see Resources
Base class for all authentication methods. Used as the default for all resouces. This is a no-op authenttication class which always returns
This method is executed by the
Resourceclass before executing the request. If the result of this method is
Falsethe request will not be executed and the response will be 401 un authorized. The basic implementation is no-op and always returns
Base class for all formatters. Subclass this to create custom formatters
dictinto a data string. Implement in derived classes for specific transport protocols
Parses a string data to python
dict. Implement in derived classes for specific transport protocols
Implements JSON formatting and parsing
A specialized resource class for using data models. Requires further implementation for data persistency
Base class for all resources.
Adds HATEOAS links to the resource. Adds href link to self. Override in subclasses to include additional functionality
as_detail(protocol=<Protocol.http: 10>, *args, **kwargs)¶
returns detail views
as_list(protocol=<Protocol.http: 10>, *args, **kwargs)¶
returns list views
as_view(endpoint, protocol, *init_args, **init_kwargs)¶
Used for hooking up the endpoints. Returns a wrapper function that creates a new instance of the resource class and calls the correct view method for it.
Given some data, generates an HTTP response. If you’re integrating with a new web framework, other than sanic or aiohttp, you MUST override this method within your subclass.
- data (string) – The body of the response to send
- status (integer) – (Optional) The status code to respond with. Default is
A response object
This method handles the actual request to the resource. It performs all the neccesary checks and then executes the relevant member method which is mapped to the method name. Handles authentication and de-serialization before calling the required method. Handles the serialization of the response
Handles the dispatch of errors
Calls format on list or detail
nested_routes(base_url, formatter: <built-in function callable> = None) → list¶
Returns an array of
Routeobjects which define additional routes on the resource. Implement in derived resources to add additional routes to the resource
- base_url – The URL prefix which will be prepended to all nested routes
- formatter – The format method to be used when parsing url variables.
By default the resource’s
route_parammethod is used, which formats the url based on which HTTP libary is used.
parse(method, endpoint, body)¶
calls parse on list or detail
Returns the arguments passed with the request in a dictionary. Returns both URL resolved arguments and query string arguments. Implemented for specific http libraries in derived classes
Returns the body of the current request. Implemented for specific http libraries in derived classes
Returns the HTTP method for the current request.
Returns the relevant representation of allowed HTTP methods for a given route. Implemented on the http library resource sub-class to match the requirements of the HTTP library
route_param(param, type=<class 'str'>)¶
Returns the route representation of a url param, pertaining to the web library used. Implemented on the http library resource sub-class to match the requirements of the HTTP library
wrap_handler(handler, protocol, **kwargs)¶
Wrap a request handler with the matching protocol handler
A configuration class for Resources. Provides all the defaults and allows overriding inside the resource’s definition using the
- name – Declare the resource’s name. If
Nonethe class name will be used. Default is
- object_class – Declare the class of the underlying data object. Used in
MongoResourceto bind the resource class to a
- query – Define a query which the resource will apply to all
listcalls. Used in
MongoResourceto apply a default query fiter. Useful for cases where the entire collection is never queried.
- sort – Define a sort directive which the resource will apply to GET requests without a unique identifier. Used in
MongoResourceto declare default sorting for collection.
- hypermedia – Specify if the a
Resourceshould format data and include HATEOAS directives, specifically link to itself. Defaults to
- fts_operator – Define the FTS (full text search) operator used in url parameters. Used in
MongoResourceto perform FTS on a collection. Default is set to q.
- incoming_list – Define the methods the resource allows access to without a primary key.
These are incoming request methods made to the resource.
Defaults to a full access
['get', 'post', 'put', 'patch', 'delete']
- incoming_detail – Same as
incoming_listbut for requests which include a primary key
- outgoing_list – Define the resource events which will be emitted without a primary key.
These are outgoing resource events which are emitted to subscribers.
Defaults to these events
['created', 'updated', 'deleted']
- outgoing_detail – Same as
outgoing_listbut for resource events which include a primary key
- formatter – Provides an instance to a formatting class the resource will be using when formatting and parsing data.
The default is
JSONFormatter. Developers can subclass
Formatterbase class and provide implementations to other formats.
- authentication – Provides and instance to the authentication class the resource will be using when authenticating requests.
NoAuthentication. Developers must subclass the
NoAuthenticationclass to provide their own resource authentication, based on the application’s authentication choices.
- channel – Defines the Channel class which the resource will emit events into. Defaults to in-memory
- name – Declare the resource’s name. If