Backends

The backends are the real meat of the documents. Where the document defines what you can do, the backends implement the how of it. Documents and backends use dictionary to communicate to each other. A backend expects a dictionary representation of the document, applies it as needed, and returns the resource as a dictionary again. Each backend must implement the following methods:

fetch
Fetch the resource from the underlying backend. Returns a dictionary.
save
Save the document to the resource in the underlying backend. Expects a dictionary representation of the document.
delete
Delete the resource from the underlying backend.

HTTP Backend

The HTTP backend uses the requests library to communicate to remote backends over HTTP. It assumes currently JSON as exchange protocol. The document methods map the following way to the HTTP backend:

uri methods

This backend uses the uri() method to determine its API endpoint. You can implement specific uri methods for each HTTP verb to be more precise. If a http specific uri method is not found, it will fallback to the default uri() method. The form of those methods is verb_uri.

class Article(Document):
    id = fields.NumberField()

    def post_uri(self):
        # Use this method for POST requests
        return "http://post_location"

    def uri(self):
        # The default uri location for all other HTTP requests
        return "http://location"

Django Backend

The django backend stores and retrieves resources using the Django ORM.

Table Of Contents

Previous topic

Mapping Fields

This Page