Skip to main content

Provides a wrapper which provides valid json to Resource methods.

Project description

PyPI Version

Add the @validate_json decorator and schema class constant to flask_restful.Resource methods (post, get, etc.) in order to validate requests meet the jsonschema.

Ensure JSON request matches schema specified in the class the wrapped method belongs to, provide that valid JSON to the method, or abort 400 with the validation error message.

from flask_restful_jsonschema import validate_json


class Users(flask_restful.Resource):
    SCHEMA_POST = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
            "password": {"type": "string"},
        },
        "required": ["email", "password"],
    }
    SCHEMA_PUT = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
            "password": {"type": "string"},
        },
    }
    SCHEMA_GET = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
        },
        "required": ["email"],
    }

    @validate_json
    def post(self, json_request):
        json_request["email"]
        json_request["password"]

    @validate_json
    def put(self, json_request):
        json_request.get("email")
        json_request.get("password")

    @validate_json
    def get(self, json_request):
        json_request["email"]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_restful_jsonschema-0.1.1.tar.gz (1.9 kB view details)

Uploaded Source

File details

Details for the file flask_restful_jsonschema-0.1.1.tar.gz.

File metadata

File hashes

Hashes for flask_restful_jsonschema-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4c81fd18d18f70d77671c540411e0077f5ef1bc050306ac361e05b5b61b613ac
MD5 e1ce358834c80da6ccd2636ec65d0c17
BLAKE2b-256 374d7272160f8bf3ad47eb22328ddaeccf775d9a466deb0d685e16a73029f0b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page