jsonapi.asyncio

Hint

This package is basically a copy of jsonapi.base, but adds to each database call an await:

# in jsonapi.base
db.get_many()

# in jsonapi.asyncio
await db.get_many()

This is is the only difference to the base API. If you know how to merge the base and async code, please create a pull request or tell me how to do it on GitHub. I don’t like having so much redudante code :(

Contains an API base application for asynchronous database adapters.

jsonapi.asyncio.api

API base application for asynchronous web frameworks.

class jsonapi.asyncio.api.API(uri, db, debug=False, settings=None)[source]

Bases: jsonapi.base.api.API

Overrides the base API to support asynchronous web frameworks.

add_type(schema, **kargs)[source]

The same as add_type(), but uses the asynchronous Unserializer as default.

handle_request(request)[source]

jsonapi.asyncio.database

Defines the interface for an asynchronous database adapters.

class jsonapi.asyncio.database.Database(api=None)[source]

Bases: jsonapi.base.database.Database

The same as the base database class, but you should inherit from this class, because we may extend it in the future.

class jsonapi.asyncio.database.Session(api)[source]

Bases: jsonapi.base.database.Session

The same as jsonapi.base.database.Session, but some methods must return awaitables:

get_relatives(resources, paths)[source]

May be overridden for performance reasons.

Does the same as jsonapi.base.database.Session.get_relatives(), but asynchronous.

Todo

Fetch the different paths in paths parallel.

jsonapi.asyncio.handler

jsonapi.asyncio.handler.base

class jsonapi.asyncio.handler.base.BaseHandler(api, db, request)[source]

Bases: object

The base class for a request handler.

Parameters:
prepare()[source]

Called directly before handle().

handle()[source]

Handles a requested and returns a asyncio.Future.

head()[source]

Handles a HEAD request.

get()[source]

Handles a GET request.

post()[source]

Handles a POST request.

patch()[source]

Handles a PATCH request.

delete()[source]

Handles a DELETE request.

jsonapi.asyncio.handler.collection

class jsonapi.asyncio.handler.collection.CollectionHandler(api, db, request)[source]

Bases: jsonapi.asyncio.handler.base.BaseHandler

Handles the collection endpoint.

prepare()[source]
get()[source]

Handles a GET request. This means to fetch many resourcs from the collection and return it.

http://jsonapi.org/format/#fetching-resources

post()[source]

Handles a POST request. This means to create a new resource and to return it.

http://jsonapi.org/format/#crud-creating

jsonapi.asyncio.handler.relationship

class jsonapi.asyncio.handler.relationship.RelationshipHandler(api, db, request)[source]

Bases: jsonapi.asyncio.handler.base.BaseHandler

Handles the relationship endpoint.

prepare()[source]
build_body()[source]

Serializes the relationship and creates the JSONapi body.

get()[source]

Handles a GET request.

http://jsonapi.org/format/#fetching-relationships

post()[source]

Handles a POST request.

This method is only allowed for to-many relationships.

http://jsonapi.org/format/#crud-updating-relationships

patch()[source]

Handles a PATCH request.

http://jsonapi.org/format/#crud-updating-relationships

delete()[source]

Handles a DELETE request.

jsonapi.asyncio.handler.resource

class jsonapi.asyncio.handler.resource.ResourceHandler(api, db, request)[source]

Bases: jsonapi.asyncio.handler.base.BaseHandler

Handles a resource endpoint.

prepare()[source]
get()[source]

Handles a GET request.

http://jsonapi.org/format/#fetching-resources

patch()[source]

Handles a PATCH request.

http://jsonapi.org/format/#crud-updating

delete()[source]

Handles a DELETE request.

jsonapi.asyncio.serializer

Contains an unserializer that works with asynchronous database drivers.

class jsonapi.asyncio.serializer.Unserializer(schema)[source]

Bases: jsonapi.base.serializer.Unserializer

Does the same as the base Unserializer, but calls the database methods with await.

create_resource(db, resource_object)[source]

The same as the base class method, but calls db async.

update_resource(db, resource, resource_object)[source]

The same as the base class method, but call the db async.

update_relationship(db, resource, relationship_name, relationship_object)[source]

The same as the base class method, but calls the db async.

extend_relationship(db, resource, relationship_name, relationship_object)[source]

The same as the base class method, but calls the db async.