How to do it...

  1. Import some core definitions from the flask package. The Flask class defines the overall application. The request object holds the current web request:
        from flask import Flask, request, jsonify, abort 
        from http import HTTPStatus

The jsonify() function will return a JSON-format object from a Flask view function. The abort() function returns an HTTP error status and ends processing of the request.


  1. Import the underlying classes, Card and Deck. Ideally, these are imported from a separate module. It should be possible to test all of the features outside the web services environment:
        from ch12_r01 import Card, Deck 

In order to properly shuffle, we'll also need the random module:

        import random 
  1. Create the Flask object. ...

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.