Decorators

Several decorators for using with supercell.api.RequestHandler implementations.

supercell.decorators.consumes(content_type, model, vendor=None, version=None)

Class decorator for mapping HTTP POST and PUT bodies to

Example:

@s.consumes(s.MediaType.ApplicationJson, model=Model)
class MyHandler(s.RequestHandler):

    def post(self, *args, **kwargs):
        # ...
        raise s.OkCreated()
Parameters:
  • content_type (str) – The base content type such as application/json
  • model (schematics.models.Model) – The model that should be consumed.
  • vendor (str) – Any vendor information for the base content type
  • version (float) – The vendor version
supercell.decorators.provides(content_type, vendor=None, version=None, default=False)

Class decorator for mapping HTTP GET responses to content types and their representation.

In order to allow the application/json content type, create the handler class like this:

@s.provides(s.MediaType.ApplicationJson)
class MyHandler(s.RequestHandler):
    pass

It is also possible to support more than one content type. The content type selection is then based on the client Accept header. If this is not present, ordering of the provides() decorators matter, i.e. the first content type is used:

@s.provides(s.MediaType.ApplicationJson)
class MyHandler(s.RequestHandler):
    ...
Parameters:
  • content_type (str) – The base content type such as application/json
  • vendor (str) – Any vendor information for the base content type
  • version (float) – The vendor version
  • default (bool) – If True and no Accept header is present, this content type is provided
Read the Docs v: latest
Versions
latest
v0.4.0
v0.3.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.