When a WSGIApplication receives a request, it creates an instance of the RequestHandler class associated with the URL path in the request. It then calls a method that corresponds with the HTTP action of the request, such as the
get() method for a HTTP GET request. The method processes the request and prepares a response, then returns. Finally, the application sends the response to the client.
The following example defines a request handler that responds to HTTP GET requests:
class AddTwoNumbers(webapp.RequestHandler): def get(self): try: first = int(self.request.get('first')) second = int(self.request.get('second')) self.response.out.write("<html><body><p>%d + %d = %d</p></body></html>" % (first, second, first + second)) except (TypeError, ValueError): self.response.out.write("<html><body><p>Invalid inputs</p></body></html>")
A request handler can define any of the following methods to handle the corresponding HTTP actions: