module DppmRestApi::Actions::Route

Overview

A series of route utilities functions that are useful to all of the Action blocks.

Direct including types

Defined in:

actions/route.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.get_prefix_with_source_name(context : HTTP::Server::Context) : DPPM::Prefix #

Get a prefix from a context, which has a source name.


[View source]
def self.prefix : DPPM::Prefix? #

[View source]
def self.prefix=(prefix : DPPM::Prefix) #

[View source]

Instance Method Detail

def build_json_array(response : IO, & : JSON::Builder -> ) #

Like #build_json_object, but builds an array instead of an object


[View source]
def build_json_object(response : IO, & : JSON::Builder -> ) #

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.


[View source]
def parse_boolean_param(key : String, from context : HTTP::Server::Context) : Bool #

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.


[View source]