June 2019
Beginner to intermediate
770 pages
19h 24m
English
We'll look at two additional features common to Flask applications and RESTful APIs:
Flask provides several clever parsing features to decompose the path in a URI. Perhaps one of the most useful parsers is used to extract individual field items from the URL string. We can use this as shown in the following example:
@app.route("/hands/<int:h>/dominoes/<int:c>")def hands(h: int, c: int) -> Tuple[Dict[str, Any], int]: if h == 0 or c == 0: return jsonify( status="Bad Request", error=[f"hands={h!r}, dominoes={c!r} is invalid"] ), HTTPStatus.BAD_REQUEST if app.env == "development": random.seed(2) b = Boneyard( ...
Read now
Unlock full access