Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install repoze.bfg.restrequest

How to install repoze.bfg.restrequest

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install repoze.bfg.restrequest
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0.1 Available View build log
Windows (64-bit)
1.0.1 Available View build log
Mac OS X (10.5+)
1.0.1 Available View build log
Linux (32-bit)
1.0.1 Available View build log
Linux (64-bit)
1.0.1 Available View build log
 
License
Repoze (BSD-like) license, http://repoze.org/licen
Dependencies
Depended by
Lastest release
version 1.0.1 on Jan 5th, 2011

Introduction

repoze.bfg.restrequest implements 4 additional Request types for use with RESTful applications.

Imagine you want to create separate views for one resource (identified by an URL) and different HTTP methods. In a default repoze.bfg project you can e.g. write:

System Message: WARNING/2 (<string>, line 10)

Literal block expected; none found.

from repoze.bfg.restrequest import IGETRequest, IPOSTRequest from webob import Response

def my_view_get(context, request): return Response("GETn")

def my_view_post(context, request): return Response("POST "+request.body+"n")

This defines one method my_view_get in case a GET request is performed on this resource and my_view_post in case a POST request is performed. You can do similar things with PUT or DELETE.

In order to enable these views you need to wire them in configure.zcml like this:

<!-- include to activate the event handler for marking REST requests -->
<include package="repoze.bfg.restrequest" />

<bfg:view for=".models.IMyModel" request_type="repoze.bfg.restrequest.interfaces.IGETRequest" view=".views.my_view_get" />

<bfg:view for=".models.IMyModel" request_type="repoze.bfg.restrequest.interfaces.IPOSTRequest" view=".views.my_view_post" />

You can do the same using repoze.bfg.convention in which case your views would look like this:

System Message: WARNING/2 (<string>, line 38)

Literal block expected; none found.

from repoze.bfg.restrequest import IGETRequest, IPOSTRequest from webob import Response

@bfg_view(request_type=IGETRequest, for_=models.IMyModel) def my_view_get(context, request): return Response("GETn")

@bfg_view(request_type=IPOSTRequest, for_=models.IMyModel) def my_view_post(context, request): return Response("POST "+request.body+"n")

Make sure you nevertheless include repoze.bfg.restrequest in your configure.zcml.

Testing your application

A simple test for the above would be to start your application and use curl to see what the result is for different methods:

$ curl http://127.0.0.1:6543/

System Message: ERROR/3 (<string>, line 58)

Inconsistent literal block quoting.

GET

$ curl http://127.0.0.1:6543/ -d "posttest" POST posttest

Changelog

1.0 - initial release (19 Oct 2008)
  • Initial release
1.0.1 - package bugfixing
  • moved HISTORY.txt to main directory so that setup.py finds and packages it.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.