Used to verify Flask route Response and Request contents.
Project description
flask-verify
A python package to verify the content of Requests and convert the return values of view functions in Flask applications.
Installation
You can install flask-verify
pip install flask-verify
Example
Consider this minimal example, where Message
is a simple dataclass.
from flask_verify.verify_json import verify_json_route
from flask import Flask, request
app = Flask(__name__)
@app.route('/example', methods=['POST'])
@verify_json_route(must_contain=('message', 'username'))
def example_route():
message = Message(request.json['username'], request.json['message'])
return message, 200
Just by writing a single decorator statement, we have:
- Ensured that the
Request
is of typeapplication/json
and contains keysmessage
andusername
, if this is not true, our server will respond with a 400 status code Response explaining the issue to the server, including the name of the first missing key if that exists. - Converted the return type to JSON,
message
object is an instance of theMessage
dataclass, thanks to our decorator, the Response will automatically be converted to a JSON containing the field names and values of the dataclass instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_verify-0.1.0.tar.gz
(24.7 kB
view hashes)
Built Distribution
Close
Hashes for flask_verify-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551efec95b585629399cb3e34e4bc7e565924ff49b81a562afc080f7c8e30ae0 |
|
MD5 | 27c631f6bd1a59969b885de21e618bbd |
|
BLAKE2b-256 | 4fcc2824a77bff0dffedd201ca2c77e47dae97b0349468721d3d7789115faf57 |