Skip to main content

This is a request handler validation tool for RESTful API endpoints.

Project description

Validator

This is a request handler validation tool for RESTful API endpoints.

How To Use

from validator import validator, ValidationError

def request_handler(req, res, next):
    # If you're familiar with Express.js req, res, next should be understood
    validation_rules = get_validation_rules()
    request_parameters = req.query
    validation_rules = {
        "q": "string|required|max:100",
        "timestamp": "string|sometimes|max:30",
        "names": "list|required|min:3",
        "code": "integer|required|"
    }
    try:
        validator(validation_rules, request_parameters)
    except ValidationError:
        return next({ "message": "The request parameters are not valid."})
    res.json({"message": "Validation successful."})

Refer to the demo.py file for further implementations.

How to Install

python -m pip install validrequest

or

python -m pip install git+https://github.com/ableinc/validator.git

Contributions

This library was designed and inspired by Jacob Lucas. Validator is a python rewrite of the original nodeJS library.

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

validrequest-0.0.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

validrequest-0.0.2-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

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