Creating a simple application and server

We'll write a very simple REST server that provides a series of hands of dominoes. This will work by routing a URI to a function that will provide the hands. The function must create a response object that includes one or more of the following items:

  • A status code: The default is 200, which indicates success.
  • Headers: The default is a minimal set of response headers with the content size.
  • Content: This can be a stream of bytes. In many cases, RESTful web services will return a document using JSON notation. The Flask framework provides us with a handy function for converting objects to JSON Notation, jsonify().

A Flask application that deals a simple hand of dominoes can be defined as follows:

from ...

Get Mastering Object-Oriented Python - Second Edition 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.