This document describes the methods proposed by cornice. It is automatically generated from the source code.
cornice.service.
Service
(name, path, description=None, cors_policy=None, depth=1, **kw)¶Contains a service definition (in the definition attribute).
A service is composed of a path and many potential methods, associated with context.
All the class attributes defined in this class or in children are considered default values.
Parameters: |
|
---|
There are also a number of parameters that are related to the support of CORS (Cross Origin Resource Sharing). You can read the CORS specification at http://www.w3.org/TR/cors/
Parameters: |
|
---|
See https://pyramid.readthedocs.io/en/1.0-branch/glossary.html#term-acl for more information about ACLs.
Service cornice instances also have methods get()
, post()
,
put()
, options()
and delete()
are decorators that can
be used to decorate views.
cornice.service.
decorate_view
(view, args, method, route_args={})¶Decorate a given view with cornice niceties.
This function returns a function with the same signature than the one you give as :param view:
Parameters: |
|
---|
cornice.resource.
resource
(depth=2, **kw)¶Class decorator to declare resources.
All the methods of this class named by the name of HTTP resources
will be used as such. You can also prefix them by "collection_"
and
they will be treated as HTTP methods for the given collection path
(collection_path), if any.
Parameters: |
|
---|
Here is an example:
@resource(collection_path='/users', path='/users/{id}')
cornice.resource.
view
(**kw)¶Method decorator to store view arguments when defining a resource with the @resource class decorator
Parameters: | kw – Keyword arguments configuring the view. |
---|
cornice.resource.
add_view
(func, **kw)¶Method to store view arguments when defining a resource with the add_resource class method
Parameters: |
|
---|
Example:
class User(object):
def __init__(self, request):
self.request = request
def collection_get(self):
return {'users': _USERS.keys()}
def get(self):
return _USERS.get(int(self.request.matchdict['id']))
add_view(User.get, renderer='json')
add_resource(User, collection_path='/users', path='/users/{id}')
cornice.resource.
add_resource
(klass, depth=1, **kw)¶Function to declare resources of a Class.
All the methods of this class named by the name of HTTP resources
will be used as such. You can also prefix them by "collection_"
and
they will be treated as HTTP methods for the given collection path
(collection_path), if any.
Parameters: |
|
---|
Here is an example:
class User(object):
pass
add_resource(User, collection_path='/users', path='/users/{id}')
cornice.validators.
extract_cstruct
(request)¶Extract attributes from the specified request such as body, url, path, method, querystring, headers, cookies, and returns them in a single dict object.
Parameters: | request (Request ) – Current request |
---|---|
Returns: | A mapping containing most request attributes. |
Return type: | dict |
cornice.validators.
colander_body_validator
(request, schema=None, deserializer=None, **kwargs)¶Validate the body against the schema defined on the service.
The content of the body is deserialized, validated and stored in the
request.validated
attribute.
Note
If no schema is defined, this validator does nothing.
Parameters: |
|
---|
cornice.validators.
colander_validator
(request, schema=None, deserializer=None, **kwargs)¶Validate the full request against the schema defined on the service.
Each attribute of the request is deserialized, validated and stored in the
request.validated
attribute
(eg. body in request.validated['body']
).
Note
If no schema is defined, this validator does nothing.
Parameters: |
|
---|