Define Web Services in Pyramid.
Project description
Overview
Cornice provides a Service class you can use to define web services in Pyramid.
Each instance of a Service class corresponds to a server path and you may implement various methods HTTP on the path with simple decorators.
Cornice will automatically return a 405 error with the right Allow header if a method that was not implemented is requested.
Cornice also provides a Sphinx directive that can be used to document your web services. The extension iterates over defined services and will automatically generate your web service documentation.
QuickStart
To use Cornice, start by including it in your project with the include method in Pyramid:
def main(global_config, **settings): ... config.include("cornice") ... return config.make_wsgi_app()
Learn more about include at http://docs.pylonsproject.org/projects/pyramid/1.0/narr/advconfig.html#including-configuration-from-external-sources
Then you can start to define web services in your views.
For example, let’s define a service where you can GET and POST a value at /values/{value}, where value is an ascii value representing the name of the value:
import json from cornice import Service values = Service(name='foo', path='/values/{value}', description="Cornice Demo") _VALUES = {} @values.get() def get_value(request): """Returns the value. """ key = request.matchdict['value'] return _VALUES.get(key) @values.post() def set_value(request): """Set the value. Returns *True* or *False*. """ key = request.matchdict['value'] try: _VALUES.set(key, json.loads(request.body)) except ValueError: return False return True
By default, Cornice uses a Json rendered.
0.1 - 2011-11-03
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cornice-0.1.tar.gz
.
File metadata
- Download URL: cornice-0.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9accfd9e2395083cb560e28d2ed6870a969eed0d529ddf568618aad99ecdcc6 |
|
MD5 | 252e732b62288525543ec79eb1afb439 |
|
BLAKE2b-256 | 90cdf5fef3c9370d3a8d44fe8bb642c1c39b5387b1e2f7c2869b759bcfd9ebaf |