adhocracy_core.rest package

Configure rest api packages.

class api_view(**settings)[source]

Bases: pyramid.view.view_config

A functionclassmethod decorator to configure a rest api view.

It works like the normal pyramid.view.view_config decorator exept the following defaults are set:

renderer='json'
route_name=API_ROUTE_NAME,
decorator = [validate_user_headers,
             validate_anonymize_header,
             validate_visibility,
             set_cache_header]

In addition it is possible to set a Schema to validate the request body or querystring:

schema=myschema

If set the validate_request_data decorator is initialized with it and added to the decorator settings.

Example:

@api_view(context=IMyContentType,
          schema=MySchema,
          request_method=POST,
          )
def post_rest_view(context:IResource, request: IRequest) -> dict:
    appstruct = request.validated
    ...
includeme(config)[source]

Include all rest views configuration.