djblets.webapi.resources.root¶
A flexible resource for the root of your API resource tree.
-
class
RootResource
(child_resources=[], include_uri_templates=True)[source]¶ Bases:
djblets.webapi.resources.base.WebAPIResource
The root of a resource tree.
This is meant to be instantiated with a list of immediate child resources. The result of
get_url_patterns()
should be included in a project’surls.py
.-
serialize_root
(request, *args, **kwargs)[source]¶ Serialize the contents of the root resource.
By default, this just provides links and URI templates. Subclasses can override this to provide additional data, or to otherwise change the structure of the root resource.
-
get_uri_templates
(request, *args, **kwargs)[source]¶ Return all URI templates in the resource tree.
REST APIs can be very chatty if a client wants to be well-behaved and crawl the resource tree asking for the links, instead of hard-coding the paths. The benefit is that they can keep from breaking when paths change. The downside is that it can take many HTTP requests to get the right resource.
This list of all URI templates allows clients who know the resource name and the data they care about to simply plug them into the URI template instead of trying to crawl over the whole tree. This can make things far more efficient.
-