Skip to content

Commit

Permalink
Merge pull request #480 from ergo/master
Browse files Browse the repository at this point in the history
docs: add examples on how to reuse pyramid routes
  • Loading branch information
leplatrem committed Apr 3, 2018
2 parents e3577ad + 0960bfc commit 42223f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cornice/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class User(object):
pass
add_resource(User, collection_path='/users', path='/users/{id}')
Alternatively if you want to reuse your existing pyramid routes:
.. code-block:: python
class User(object):
pass
add_resource(User, collection_pyramid_route='users',
pyramid_route='user')
"""

services = {}
Expand Down
9 changes: 9 additions & 0 deletions docs/source/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ As you can see, you can define methods for the collection (it will use the
**path** argument of the class decorator. When defining collection_* methods, the
path defined in the **collection_path** will be used.

Here is an example how to reuse existing pyramid routes instead of registering
new ones:

.. code-block:: python
@resource(collection_pyramid_route='users', pyramid_route='user')
class User(object):
....
Validators and filters
======================

Expand Down
11 changes: 11 additions & 0 deletions docs/source/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ this way:
def flush_post(request):
return {"Done": True}
Example above registers new routes in pyramid registry, you might want to
reuse existing routes from your application too.

.. code-block:: python
from cornice import Service
flush = Service(name='flush',
description='Clear database content',
pyramid_route='flush_path')
See :class:`cornice.service.Service` for an exhaustive list of options.

Imperatively
Expand Down

0 comments on commit 42223f6

Please sign in to comment.