Multiple layers of REST services

It's common for a complex RESTful application to use a database to save persistent objects, as well as change the state of those persistent objects. This often leads to a multi-tier web application. One view of a design will focus on these three tiers:

  • Presentation to people is handled by HTML pages, possibly including JavaScript. The HTML content often starts as templates, and a tool such as Jinja (http://jinja.pocoo.org) is used to inject data into the HTML template. In many cases, the presentation layer is a separate Flask application focused on supporting features of a rich user experience, including stateful sessions and secure authentication. This layer will make a request to the application layer via RESTful requests.
  • Application processing is done via a RESTful server that models the problem domain. Concerns such as user authentication or stateful interactions are not part of this layer.
  • Persistence is done via a database of some kind. In many practical applications, a complex module will define an init_app() function to initialize a database connection.

As we saw in Chapter 11, Storing and Retrieving Objects with Shelve, it's quite easy to have a database that has an interface similar to a dictionary. We'll leverage this simple-looking interface to create a RESTful service that tracks a stateful object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset