From 5cd6bd90369d5937a6571a70bff4d59551ec9325 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 16 Nov 2008 00:11:13 +0000 Subject: Don't mention REST; I don't understand it obviously. --- docs/narr/events.rst | 17 +++-------------- 1 file 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"/> - - -