Validates and retrieves typed fields from a single document.
Sanitizes a dict-like document by checking it against a list of field spec, and returning only those fields specified.
Parameters: |
|
---|---|
Raises: | BadRequest if any field is missing or not an instance of the specified type |
Returns: | A filtered dict containing only the fields listed in the spec |
Validates and retrieves a typed field from a document.
This function attempts to look up doc[name], and raises appropriate errors if the field is missing or not an instance of the given type.
Parameters: |
|
---|---|
Raises: | BadRequest if the field is missing or not an instance of value_type |
Returns: | value obtained from doc[name] |
Read a required Client-ID from a request.
Parameters: | req – Request object |
---|---|
Raises: | BadRequest if the Client-ID header is missing or does not represent a valid UUID |
Returns: | A UUID object |
Handles generic Exceptions in API endpoints
This decorator catches generic Exceptions and returns a generic Response.
Validates a document and drops undesired fields.
Parameters: |
|
---|---|
Raises: | DocumentTypeNotSupported, TypeError |
Returns: | A sanitized, filtered version of the document. If the document is a list of objects, each object will be filtered and returned in a new list. If, on the other hand, the document is expected to contain a single object, that object’s fields will be filtered and the resulting object will be returned. |