Response class

All requests need a response, the response class creates an object for every request, the one can be used to send custom headers or HTTP status codes.

The second argument for the dispatch method is the response object:

1
2
3
4
5
6
7
from zunzuncito import tools

class APIResource(object):


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

Response object contents

Name Description
log logger intance.
request_id The request id.
headers A CaseInsensitiveDict instance, for storing the headers.
status Default 200 an int respresenting an HTTP status code.
start_response The start_response() Callable.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from zunzuncito import tools


class APIResource(object):

    def __init__(self):
        self.headers['Content-Type'] = 'text/html; charset=UTF-8'

    def dispatch(self, request, response):

        response.headers.update(self.headers)

        try:
            name = request.path[0]
        except Exception:
            name = ''

       if name:
             return 'Name: ' + name

        response.status =  406

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