There's more...

In the Implementing web services with WSGI recipe, we wrapped the application in a generic test that confirmed that the request had one of two properties. We used the following two rules:

  • An Accept header that required JSON
  • A query string with $format=json in it

If we're writing a complex RESTful application server, we often want this kind of test applied to all of the view functions. We'd rather not repeat the code for this test.

We canof coursecombine the WSGI solution from the Implementing web services with WSGI recipe with the Flask application to build a composite application. We can also accomplish this entirely within Flask. The pure Flask solution is a bit simpler than the WSGI solution, making it desirable.

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.