:fire:flask-json-api:fire:: Flask boilerplate setup code for REST application/json API’s
The Flask JSON API package provides boilerplate code for setting up REST based apps written with Flask.
Installing flask-json-api
pip install flask-json-api
Using Flask JSON API
Using Flak JSON API is as easy as initiating it with the Flask app instance:
from flask import Flask
from flask_json_api import FlaskJsonApi
app = Flask(__name__)
flask_json_api = FlaskJsonApi(app)
How it works
This package requires the application/json content-type header, or else an HTTP error will be returned:
import requests
# providing the application/json content type will succeed
url = 'http://localhost:5000/api'
headers = {'Content-Type': 'application/json'}
r = requests.get(url, headers=headers)
assert r.status_code == 200
# not providing the application/json content type will fail
url = 'http://localhost:5000/api'
r = requests.get(url)
assert r.status_code == 415
Register expected and unexpected exception types:
- Although all errors should be returned as JSON, you can register different exception types as:
Expected Errors - will return 400 http error code (and logged with WARNING level)
Unexpected Errors - will return 500 http error code (and logged with ERROR level)
class ExpectedError(Exception):
"""Expected error, such as Data Validation Error"""
class UnexpectedError(Exception):
"""Unexpected error, such as database is not accessible"""
flask_json_api.register_expected_exception(ExpectedError)
flask_json_api.register_unexpected_exception(UnexpectedError)
Whitelisting paths that do not require application/json
Whenever the flask.request.path starts with any of these exclude_paths, then the application/json header won’t be required.
flask_json_api.set_application_json_exclude_paths(exclude_paths=['/home'])
# Please note that if the exclude_paths will contain '/',
# then no path will require the application/json content-type
Metadata
Release files for flask-json-api 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask-json-api-1.0.0.tar.gz | 3.5 kB | Without provenance | Details for flask-json-api-1.0.0.tar.gz |
Release files / flask-json-api-1.0.0.tar.gz
| Download URL | flask-json-api-1.0.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fc21069bc85ba1968c9fd36d2c8d4b1e0657568ed94735d07ef628e5d4fac2b
|
|
BLAKE2b-256 checksum How to use checksums |
f987d486b9b1381a896b77e196e097e37dfe6611c9ba5d805b6a6277adec6e3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for flask-json-api 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.