summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2013-03-12 13:02:23 -0400
committerRyan Petrello <lists@ryanpetrello.com>2013-03-12 13:02:23 -0400
commit125b3ad2e00348fdc3a861b81edc2d405eb15ddc (patch)
tree08c152a61e49f8484a26a4493fcf2bbc93b467ba
parent2c58651b043eb7261487be6bfa40e9d90d896a01 (diff)
downloadpecan-125b3ad2e00348fdc3a861b81edc2d405eb15ddc.tar.gz
Add documentation for returning specific HTTP status codes.
-rw-r--r--docs/source/routing.rst29
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/source/routing.rst b/docs/source/routing.rst
index ac6a9b2..e27baf6 100644
--- a/docs/source/routing.rst
+++ b/docs/source/routing.rst
@@ -134,6 +134,35 @@ methods on your controller objects provides additional flexibility for
processing all or part of a URL.
+Setting a Return Status Code
+--------------------------------
+
+Setting a specific HTTP response code (such as ``201 Created``) is simple:
+
+::
+
+ from pecan import expose, response
+
+ class RootController(object):
+
+ @expose('json')
+ def hello(self):
+ response.status = 201
+ return {'foo': 'bar'}
+
+Pecan also comes with ``abort``, a utility function for raising HTTP errors:
+
+::
+
+ from pecan import expose, abort
+
+ class RootController(object):
+
+ @expose('json')
+ def hello(self):
+ abort(404)
+
+
Routing to Subcontrollers with ``_lookup``
------------------------------------------