Tornado – Request Handlers


In tornado,

  • tornado.web.RequestHandler maps URLs to subclasses and
  • tornado.web.Application class starts a server at the beginning with certain settings

For instance, in the example below:

  • When a HTTP GET request is made to http://127.0.0.1:8888/, class Hello handles it & requests made to http://127.0.0.1:8888/user are catered by class User
  • A web form  is rendered to the user when the client browses (Http Get) to /user
  • When the client fills in the form and clicks on ‘Submit Query’, a HTTP POST request is generated on /user URL
  • This request is then served by the post() method of handler class ‘User’ and the message with username and designation is rendered on the browser

Code

Form presented to the client

 

 

Response from web server

Advertisements

One thought on “Tornado – Request Handlers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s