- Start with the Parsing the query string in a request recipe as a template for a Flask application. We'll be changing the view functions in that example:
from flask import Flask, jsonify, request, abort, make_response from http import HTTPStatus dealer = Flask('dealer')
- Import any additional modules. In this case, we'll use the uuid module to create a unique key for a shuffled deck:
import uuid
We'll also use the Werkzeug BadRequest response. This allows us to provide a detailed error message. This is a little nicer than using abort(400) for an erroneous request:
from werkzeug.exceptions import BadRequest
- Define the global state. This includes the collection of decks. It also includes the random number generator. For testing ...