REST with JSON has become the de facto standard in cross-application communication technologies for web-based applications.
It's a very effective protocol, and the fact that the definition can be understood by everyone made it popular pretty quickly.
Also, a rapid REST implementation can be rolled out pretty quickly compared to other more complex communication protocols.
As the Python standard library provides the foundations we needed to build WSGI-based applications, it's not hard to extend our existing recipe to support REST-based dispatch of requests.
We are going to use WSGIApplication
from our previous recipe, but instead of registering a function for a root, we are going to register a particular class able to dispatch based on the request method.
- All the REST classes we want to implement must inherit from a single
RestController
implementation:
class RestController: def __call__(self, req, resp): method = req.environ['REQUEST_METHOD'] action ...