module DppmRestApi::Actions::Route
Overview
A series of route utilities functions that are useful to all of the Action blocks.
Direct including types
- DppmRestApi::Actions::App
- DppmRestApi::Actions::Groups
- DppmRestApi::Actions::Pkg
- DppmRestApi::Actions::Service
- DppmRestApi::Actions::Src
- DppmRestApi::Actions::User
Defined in:
actions/route.crClass Method Summary
-
.get_prefix_with_source_name(context : HTTP::Server::Context) : DPPM::Prefix
Get a prefix from a context, which has a source name.
- .prefix : DPPM::Prefix?
- .prefix=(prefix : DPPM::Prefix)
Instance Method Summary
-
#build_json_array(response : IO, & : JSON::Builder -> )
Like
#build_json_object
, but builds an array instead of an object -
#build_json_object(response : IO, & : JSON::Builder -> )
Build JSON directly to the HTTP response IO.
-
#parse_boolean_param(key : String, from context : HTTP::Server::Context) : Bool
This method parses a boolean value from a query parameter.
Class Method Detail
Get a prefix from a context, which has a source name.
Instance Method Detail
Like #build_json_object
, but builds an array instead of an object
Build JSON directly to the HTTP response IO. This yields inside of an object labelled "data", like
{"data": {"whatever": "you build"}}
Since it's in an object, one needs to use JSON::Builder#field
at the
top-level within the block.
NOTE One must also ensure that the block does not raise an exception -- this would result in invalid JSON being output as the response body. For example...
build_json_object do
raise InternalServerError.new "Oh no!"
end
...would result in the following response body...
{"data":{"errors": [{"type": "InternalServerError", "status_code": 500, "message": "oh no!"}]}
...which is not valid JSON due to the unclosed object written at the beginning.
This method parses a boolean value from a query parameter. It returns true when the query parameter is specified, but empty; false when the parameter is not specified (null); and otherwise raises a BadRequest exception.