From 125b3ad2e00348fdc3a861b81edc2d405eb15ddc Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 12 Mar 2013 13:02:23 -0400 Subject: Add documentation for returning specific HTTP status codes. --- docs/source/routing.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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`` ------------------------------------------ -- cgit v1.2.1