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)¶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}')