diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-11-16 00:11:13 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-11-16 00:11:13 +0000 |
| commit | 5cd6bd90369d5937a6571a70bff4d59551ec9325 (patch) | |
| tree | fc110a8f16665385080eab11e810a0a0ca57ebd2 | |
| parent | 070b9d6240e97c17d341df7d635d4e36b8fd2f16 (diff) | |
| download | pyramid-5cd6bd90369d5937a6571a70bff4d59551ec9325.tar.gz pyramid-5cd6bd90369d5937a6571a70bff4d59551ec9325.tar.bz2 pyramid-5cd6bd90369d5937a6571a70bff4d59551ec9325.zip | |
Don't mention REST; I don't understand it obviously.
| -rw-r--r-- | docs/narr/events.rst | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/docs/narr/events.rst b/docs/narr/events.rst index fbc88bf23..6bdbb59f4 100644 --- a/docs/narr/events.rst +++ b/docs/narr/events.rst @@ -107,10 +107,11 @@ Using An Event to Vary the Request Type The most common usage of the ``INewRequestEvent`` is to attach an :term:`interface` to the request to be able to differentiate, for -example, a request issued by a browser from a request issued by a REST +example, a request issued by a browser from a request issued by a JSON client. This differentiation makes it possible to register different views against different ``request_type`` interfaces; for instance, -depending on request headers, you might return JSON or XML data. +depending on the presence of a request header, you might return JSON +data. To do this, you should subscribe an function to the ``INewRequest`` event type, and you should use the ``zope.interface.alsoProvides`` API @@ -123,10 +124,6 @@ object provided by the event. Here's an example. from zope.interface import alsoProvides from zope.interface import Interface - class IRESTRequest(Interface): - """ A request from a REST client that sets an Accept: - application/xml header""" - class IJSONRequest(Interface): """ A request from a JSON client that sets and Accept: application/json header """ @@ -136,8 +133,6 @@ object provided by the event. Here's an example. accept = request.headers.get('accept', '') if 'application/json' in accept: alsoProvides(request, IJSONRequest) - elif 'application/xml' in accept: - alsoProvides(request, IRestRequest) Then in your view registration ZCML, you can use the ``request_type`` attribute to point at different view functions depending upon the @@ -155,12 +150,6 @@ request type interfaces for the same model object. request_type="repoze.bfg.interfaces.IRequest" view=".views.html_view"/> - <!-- xml (REST) view --> - <bfg:view - for=".models.MyModel" - request_type=".interfaces.IRESTRequest" - view=".views.rest_view"/> - <!-- JSON view --> <bfg:view for=".models.MyModel" |
