Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ludusrusso/flask_voluptuous
A simple flask extension for data validation with Voluptuous
https://github.com/ludusrusso/flask_voluptuous
Last synced: 20 days ago
JSON representation
A simple flask extension for data validation with Voluptuous
- Host: GitHub
- URL: https://github.com/ludusrusso/flask_voluptuous
- Owner: ludusrusso
- License: bsd-3-clause
- Created: 2017-10-02T09:15:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-30T08:48:18.000Z (almost 4 years ago)
- Last Synced: 2024-12-09T03:06:39.497Z (about 1 month ago)
- Language: Python
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flask_voluptuous
A simple flask extension for data validation with Voluptuous## Usage
```python
from flask import Flask
from flask_voluptuous import expect, Schema, Requiredapp = Flask(__name__)
@app.route('/')
@expect(Schema({
Required('name'): str
}), 'args')
def index(args):
return 'name: {}'.format(args['name'])if __name__ == '__main__':
app.run(debug=True)
```The `/` route requires a `name` param in the request arguments.
This data are accesible throw the `args` arguments passed to the function.If the data is not submitted, we get an 406 error:
```
$ http http://127.0.0.1:5000/?other=ludusrusso
HTTP/1.0 406 NOT ACCEPTABLE
Content-Length: 160
Content-Type: text/html
Date: Mon, 02 Oct 2017 10:44:33 GMT
Server: Werkzeug/0.12.2 Python/3.6.1406 Not Acceptable
Not Acceptable
extra keys not allowed @ data['other']
``````
$ http http://127.0.0.1:5000/?name=ludusrusso
HTTP/1.0 200 OK
Content-Length: 16
Content-Type: text/html; charset=utf-8
Date: Mon, 02 Oct 2017 10:42:18 GMT
Server: Werkzeug/0.12.2 Python/3.6.1name: ludusrusso
```