io.aviso.rook

Rook is used to map the functions of a namespace as web request endpoints, based largely on metadata on the functions.

default-options

Default options when generating the routing table.

Defines a base set of argument resolvers (default-arg-resolvers), an empty map of constraints, an empty list of interceptors, and an empty map of interceptor definitions.

gen-table-routes

(gen-table-routes namespace-map options)

Generates a vector of Pedestal table routes for some number of namespaces.

The namespace-map is a map from URL prefix (e.g., “/users”) to a Rook namespace definition.

The Rook namespace definition is a map with keys that define how Rook will map functions in the namespace as routes and handlers in the returned table.

:ns
A symbol identifying the namespace. Rook will require the namespace and scan it for functions to create routes for.
:nested
A namespace map of nested namespaces; these inherit the prefix and other attributes of the containing namespace.
:arg-resolvers
Map from keyword to argument resolver generator. This map, if present, is merged into the containing namespaces’s map of argument resolvers.
An argument resolver generator is passed a symbol (the parameter) and returns a resolver function. The resolver function is invoked every time the endpoint function is invoked: it is passed the Pedestal context, and returns the value for the parameter.
:constraints
Map from keyword to regular expression. This map will be inherted and extended by nested namespaces.
:interceptors
Vector of Pedestal interceptors for the namespace. These interceptors will apply to all routes. Individual routes may define additional interceptors.

Each namespace may define metadata for :arg-resolvers, :constraints, and :interceptors. The supplied values are merged, or concatenated, to define defaults for any mapped functions in the namespace, and for any nested namespaces.

Alternately, a namespace definition may just be a symbol, used to identify the namespace.

Mapped functions will have a :rook-route metadata value. This consists of a method (:get, :post, etc.), a path string, and optionally, a map of constraints.

Mapped functions should have a single arity.

Each parameter of the function must have metadata identifying how the argument value is to be generated; these are defined by the effective arg-resolvers for the function.

The options map provides overrides of default-options. Supplied options are deep merged into the defaults.

The :interceptor-defs option provides extra levels of indirection between an endpoint and the interceptors it requires. It allows for interceptors to be specified as a keyword. The corresponding value in the interceptor-defs map may either be a previously instantiated interceptor, or can by a function with the ^:endpoint-interceptor-fn meta data.

In the latter case, a map definining the endpoint is passed to the generator function, which returns an interceptor.