Request class

When receiving a request a request object is created and passed as an argument to the dispatch method of the APIResource class

The first argument for the dispatch method is the request object:

1
2
3
4
5
6
7
from zunzuncito import tools

class APIResource(object):


    def dispatch(self, request, response):
        """ your code goes here """

Request object contents

Name Description
log logger intance
request_id The request id
environ The wsgi environ
URI REQUEST_URI or PATH_INFO
host The host name.
method The request method (GET, POST, HEAD, etc)
path list of URI elements
resource Name of the API resource
version Current version
vroot Name of the vroot

Example

 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
from urlparse import parse_qsl
from zunzuncito import tools

class APIResource(object):


    @tools.allow_methods('get, post')
    def dispatch(self, request, response):

       """
       log this request
       """
       request.log.info(tools.log_json({
           'API': request.version,
           'Method': request.method,
           'URI': request.URI,
           'vroot': request.vroot
       }, True))

       if request.method == 'POST':
           data = dict(parse_qsl(request.environ['wsgi.input'].read(), True))
       else
           data = dict(parse_qsl(request.environ['QUERY_STRING'], True))

       data = {k: v.decode('utf-8') for k, v in data.items()}

       return tools.log_json(data)

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