WebOb

What is it?

WebOb is a Python library that provides wrappers around the WSGI request environment, and an object to help create WSGI responses. The objects map much of the specified behavior of HTTP, including header parsing, content negotiation and correct handling of conditional and range requests.

This helps you create rich applications and valid middleware without knowing all the complexities of WSGI and HTTP.

Why ?

The ZunZun instance allows you to handle the request by following defined routes and by calling the dispatch method, the way you process the request is up to you, you can either do all by your self or use tools that can allow you to simplify this process, for this last one, WebOb is a library that integrates very easy and that may help you to parse the GET, POST arguments, set/get cookies, etc; with out hassle.

Example

The following code, handles the request for http://api.zunzun.io/webob.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from webob import Request
from zunzuncito import tools


class APIResource(object):


    def dispatch(self, request, response):
        req = Request(request.environ)

        data = {}
        data['req-GET'] = req.GET
        data['req-POST'] = req.POST
        data['req-application_url'] = req.application_url
        data['req-body'] = req.body
        data['req-content_type'] = req.content_type
        data['req-cookies'] = req.cookies
        data['req-method'] = req.method
        data['req-params'] = req.params
        data['req-path'] = req.path
        data['req-path_info'] = req.path_info
        data['req-path_qs'] = req.path_qs
        data['req-path_url'] = req.path_url
        data['req-query_string'] = req.query_string
        data['req-script_name'] = req.script_name
        data['req-url'] = req.url

        return tools.log_json(data, 4)

Basically you only need to pass the environ argument to the webob.Request:

def dispatch(self, environ):
    req = Request(environ)
    """ your code goes here """

See also

WebOb Request

GAE

When using google app engine you need to add this lines to your app.yaml file in order to be available to import webob:

libraries:
- name: webob
  version: latest

Many thanks Paw - The ultimate REST client for Mac. for supporting Open Source projects.

paw

A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.

Donating helps ensure continued support, development and availability.

dalmp


comments powered by Disqus