Skip to content

Latest commit

 

History

History
73 lines (47 loc) · 1.79 KB

examples.rst

File metadata and controls

73 lines (47 loc) · 1.79 KB

Examples

Before we proceed let's setup a virtualenv environment, activate it and install:

$ pip install wheezy.http

Hello World

helloworld.py shows you how to use wheezy.http in a pretty simple WSGI application:

../demos/hello/helloworld.py

Let have a look through each line in this application.

Request Handler

First of all let's take a look what is request handler:

../demos/hello/helloworld.py

It is a simple callable of form:

def handler(request):
    return response

In wheezy.http there are no dependencies between :py~wheezy.http.request.HTTPRequest and :py~wheezy.http.response.HTTPResponse.

While wheezy.http doesn't prescribe what is a router, we add here a simple router middleware. This way you can use one of available alternatives to provide route matching for your application.

../demos/hello/helloworld.py

There is a separate python package wheezy.routing that is recommended way to add routing facility to your application.

Finally we create the entry point that is an instance of :py~wheezy.http.application.WSGIApplication.

../demos/hello/helloworld.py

The rest in the helloworld application launches a simple wsgi server. Try it by running:

$ python helloworld.py

Visit http://localhost:8080/.

Guest Book

TODO