magpie.api.generic
¶
Module Contents¶
Functions¶
|
Overrides default HTTP. |
|
Overrides the default |
|
Overrides the default |
|
Guess the best applicable response |
|
Tween that validates that the specified request |
|
Tween that obtains the request |
|
Obtains additional exception content details about the |
|
Obtains additional content details about the |
-
magpie.api.generic.
internal_server_error
(request: pyramid.request.Request) → pyramid.httpexceptions.HTTPException[source]¶ Overrides default HTTP.
-
magpie.api.generic.
not_found_or_method_not_allowed
(request: pyramid.request.Request) → pyramid.httpexceptions.HTTPException[source]¶ Overrides the default
HTTPNotFound
[404] by appropriateHTTPMethodNotAllowed
[405] when applicable.Not found response can correspond to underlying process operation not finding a required item, or a completely unknown route (path did not match any existing API definition). Method not allowed is more specific to the case where the path matches an existing API route, but the specific request method (GET, POST, etc.) is not allowed on this path.
Without this fix, both situations return [404] regardless.
Overrides the default
HTTPForbidden
[403] by appropriateHTTPUnauthorized
[401] when applicable.Unauthorized response is for restricted user access according to missing credentials and/or authorization headers. Forbidden response is for operation refused by the underlying process operations or due to insufficient permissions.
Without this fix, both situations return [403] regardless.
In case the request references to Magpie UI route, it is redirected to
magpie.ui.home.HomeViews.error_view()
for it to handle and display the error accordingly.
-
magpie.api.generic.
guess_target_format
(request: pyramid.request.Request) → Tuple[Str, bool][source]¶ Guess the best applicable response
Content-Type
header according to requestAccept
header andformat
query, or defaulting toCONTENT_TYPE_JSON
.- Returns
tuple of matched MIME-type and where it was found (
True
: header,False
: query)
-
magpie.api.generic.
validate_accept_header_tween
(handler: Callable[[Request], Response], registry: pyramid.registry.Registry) → Callable[[Request], Response][source]¶ Tween that validates that the specified request
Accept
header orformat
query (if any) is a supported one by the application and for the given context.- Raises
HTTPNotAcceptable – if desired
Content-Type
is not supported.
-
magpie.api.generic.
apply_response_format_tween
(handler: Callable[[Request], HTTPException], registry: pyramid.registry.Registry) → Callable[[Request], Response][source]¶ Tween that obtains the request
Accept
header orformat
query (if any) to generate the response with the desiredContent-Type
.The target
Content-Type
is expected to have been validated byvalidate_accept_header_tween()
beforehand to handle not-acceptable errors.The tween also ensures that additional request metadata extracted from
get_request_info()
is applied to the response body if not already provided by a previous operation.