pecan-notario
JSON validation for Pecan with Notario (http://notario.cafepais.com).
In its simplest form, you need to define a schema and decorate the controller method, like:
schema = ('foo', True)
@expose()
@validate(schema)
def some_controller(self, **kw):
return dict()
The above controller method, using a Notario schema, will require a foo key and a True value otherwise it will (by default) set the HTTP response to a 400 (invalid request) and add the validation error to request.pecan['schema'].errors.
Using a handler
If more granular control is needed when dealing with an error condition, a handler can be passed in to the decorator to deal with errors explicitly.
@expose()
@validate(some_schema, '/some/handler')
def some_controller(self, **kw):
return dict()
In this situation ‘/some/handler’ would be a controller method that can deal directly with the error that was slapped onto the request object (on request.validation_error).
Notario exceptions will include a reason attribute that will contain the specific error message that was raised if a custom validator failed with an error message. In this case, a handler would access this Notario exception attribute like:
request.validation_error.reason
Metadata
Release files for pecan-notario 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pecan-notario-0.0.3.tar.gz | 5.3 kB | Details |
Release files / pecan-notario-0.0.3.tar.gz
| Download URL | pecan-notario-0.0.3.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92114160ee39832d9dd523f1859ea9ba7d8260a0972eb5140fda9cfc39fd8536
|
|
BLAKE2b-256 checksum How to use checksums |
2795acc1c292afd73065d9433092247ec3a9edeccd3df4069236ba11f51ccea1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |