amelinium.api
added in 1.0.0
API helpers for amelinium.
add-body
macro
(add-body req & body)
Adds a response body to a request map req
under its key :response/body
using qassoc
. The body is a result of evaluating expressions passed as additional arguments (body
). Returns updated req
. Assumes that req
is always a map.
add-header
macro
(add-header req header-name & body)
Adds a header header
to :response/headers
map of the req
using built-in function qassoc
. If a header name argument is a literal keyword, a character, a number, or a literal string, it will be converted to a string literal and placed as qassoc
argument. Otherwise it will be left as is and wrapped into a call to io.randomseed.utils/some-str
to ensure the result is a string run-time. All arguments of the body are used to calculate a value of the header. Assumes that req
is always a map.
add-headers
macro
(add-headers req header-name header-value)
(add-headers req header-name header-value & more)
Adds headers with associated values to :response/headers
map of the req
using built-in function qassoc
. If any header name argument is a literal keyword, a character, a number, or a literal string, it will be converted to a string literal and placed as an argument passed to qassoc
. Otherwise it will be left as is and wrapped in a call to io.randomseed.utils/some-str
to ensure at run-time that the result will be a string. Missing header value, if any, will be padded with nil
.
add-missing-sub-status
(add-missing-sub-status req sub-status)
(add-missing-sub-status req sub-status sub-key)
(add-missing-sub-status req sub-status sub-key main-key)
(add-missing-sub-status req sub-status sub-key main-key tr-sub)
(add-missing-sub-status req sub-status sub-key main-key sub-title-key sub-desc-key see-also-key)
(add-missing-sub-status req sub-status sub-key main-key sub-title-key sub-desc-key see-also-key tr-sub)
add-missing-sub-status-to-response
(add-missing-sub-status-to-response req out sub-status)
(add-missing-sub-status-to-response req out sub-status sub-key)
(add-missing-sub-status-to-response req out sub-status sub-key main-key)
(add-missing-sub-status-to-response req out sub-status sub-key main-key tr-sub)
(add-missing-sub-status-to-response req out sub-status sub-key main-key sub-title-key sub-desc-key see-also-key)
(add-missing-sub-status-to-response req out sub-status sub-key main-key sub-title-key sub-desc-key see-also-key tr-sub)
add-status
macro
(add-status req & body)
Adds response status to a request map req
under its key :response/status
using qassoc
. The status is a result of evaluating expressions passed as additional arguments. Returns updated req
. Assumes that req
is always a map.
anti-spam-code
(anti-spam-code config)
(anti-spam-code config num)
(anti-spam-code config num rng)
Generates anti-spam value pairs string containing randomly selected fields and values using validators/gen-required
.
assoc-body
macro
(assoc-body req k v)
(assoc-body req k v & more)
Adds keys with associated values to :response/body
map of the req
using qassoc
. If any key argument is a literal keyword, a character, or a literal string, it will be converted to a keyword literal and placed as qassoc
argument. Otherwise it will be left as is and wrapped into a call to io.randomseed.utils/some-keyword
to ensure the result is a keyword run-time. Missing last value, if any, will be padded with nil
. If there is no body or the body is empty, it will initialize it with a map expression, otherwise it will use assoc
. Assumes that req
is always a map.
auth-page
(auth-page req)
(auth-page req lang-id)
Returns a path for the authentication page. The page must have ID of :user/welcome
.
auth-page?
(auth-page? req)
(auth-page? req ring-match)
Returns true if the current (or given as a match) page is an authentication page (has :auth-page? route data set to a truthy value).
body-add-session-id
(body-add-session-id req)
(body-add-session-id req smap)
(body-add-session-id req session-key)
(body-add-session-id req smap field)
(body-add-session-id req session-key field)
Adds session ID field to the response body (:response/body
) of the given request map req
. Works only on a valid sessions, having :id
field set.
body-add-session-status
(body-add-session-status req)
(body-add-session-status req smap)
(body-add-session-status req session-key)
(body-add-session-status req smap translate-sub)
(body-add-session-status req session-key translate-sub)
Gets the value of :response/status
key of the given req
and if it is set to :auth/session-error
or :error/session
, adds :session-status
to a response body with a value set to a result of calling session-status
on a current session. If there is no session error detected, it simply calls body-add-session
to add session ID to the response body.
current-page-id
(current-page-id req-or-match)
Returns an identifier of a current page if it is defined for a HTTP route.
current-page-id-or-path
(current-page-id-or-path req)
Returns an identifier of a current page if it is defined for a HTTP route or a path if the page name is not defined.
go-to
(go-to)
(go-to req)
(go-to url)
(go-to req url)
(go-to req name-or-path)
(go-to req name-or-path path-params)
(go-to req name-or-path path-params query-params)
(go-to req name-or-path lang)
(go-to req name-or-path lang path-params)
(go-to req name-or-path lang path-params query-params)
(go-to req name-or-path lang path-params query-params & more)
Uses the localized-page
function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str
key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil
.
guess-lang-param
(guess-lang-param)
(guess-lang-param src)
For the given src argument, tries to obtain a language ID. If it’s a map it looks for :param
key and for :language/settings
if that fails. If :language/settings
is found, it will try to get :param, assuming it’s a map too. If the argument is not a map it will simply convert it into a keyword (without a namespace). If all of that fails (e.g. the src is nil) then the :lang keyword is returned.
hard-lock-time
(hard-lock-time user)
Gets a hard-lock time for a given user specified by a map having the :locked key.
hard-locked?
(hard-locked? user)
Returns true if the given user map contains the :locked key and a value associated with it is not nil. Does not connect to a database.
has-param?
(has-param? match param)
Checks if the given route match can be parameterized with a parameter of the given id.
lang-redir
(lang-redir req)
Redirects to a best-suited language version of the URI. Uses :browser
pickers chain to get the right language if the path is language-parameterized.
localized-page
(localized-page req)
(localized-page req name-or-path)
(localized-page req name-or-path path-params)
(localized-page req name-or-path path-params query-params)
(localized-page req name-or-path lang)
(localized-page req name-or-path lang path-params)
(localized-page req name-or-path lang path-params query-params)
(localized-page req name-or-path lang lang-required?)
(localized-page req name-or-path lang path-params lang-required?)
(localized-page req name-or-path lang path-params query-params lang-required?)
(localized-page req name-or-path lang path-params query-params lang-required? name-path-fallback?)
(localized-page req name-or-path lang path-params query-params lang-required? name-path-fallback? router)
(localized-page _ name-or-path lang path-params query-params lang-required? name-path-fallback? router language-settings-or-param)
Generates a page path for the given page identifier and language identifier. When called with just a request map, returns a path of the current page but re-generated to support current language in use (taken from :language/str
key of the request map).
The optional name-path-fallback?
argument, when set to a truthy value (true
by default), causes non-matching route identifier to be retried by extracting its path and calling this function for that path given as a string.
The optional lang-required?
argument (set to false
when not given) enables extra check eliminating pages which do not support the given language parameter. Example:
(localized-page req :login-page :pl true)
will fail if there is no parameter :lang
handled by the route named :login-page
.
When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.
Additional path parameters (path-params
) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params
when matching by path causes them to be silently ignored.
Additional query parameters (query-params
) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.
If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params
).
When the lang-required?
is set to false
(default) and a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).
When the lang-required?
is set to false
(default) and a path is given but it does not require language parameter plus the name-path-fallback?
argument is set to :brute-force
, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id
defined, and the given path is /users/
with language set to :pl
, then it will match /users/pl
even though the parameter is not related to a language.
When the lang-required?
is set to true
and a path is given but it does not require a language parameter, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires language parameter.
localized-path
(localized-path)
(localized-path req)
(localized-path req name-or-path)
(localized-path req name-or-path lang)
(localized-path req name-or-path lang params)
(localized-path req name-or-path lang params query-params)
(localized-path name-or-path lang params query-params router language-settings-or-param)
Creates a URL on a basis of route name or a path.
Uses very optimistic matching algorithm. Tries to obtain language from user settings and client settings if the path does not contain language information. Uses the :default
language picker.
Non-matching route identifier is retried by extracting its path and calling the localized-page
function for that path given as a string.
If a page found does not have a language parameter it is accepted too.
When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.
Additional path parameters (params
) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving params
when matching by path causes them to be silently ignored.
Additional query parameters (query-params
) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.
If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using params
).
When a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).
localized-see-other
(localized-see-other)
(localized-see-other req)
(localized-see-other url)
(localized-see-other req url)
(localized-see-other req name-or-path)
(localized-see-other req name-or-path path-params)
(localized-see-other req name-or-path path-params query-params)
(localized-see-other req name-or-path lang)
(localized-see-other req name-or-path lang path-params)
(localized-see-other req name-or-path lang path-params query-params)
(localized-see-other req name-or-path lang path-params query-params & more)
Uses the localized-page
function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str
key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil
.
localized-temporary-redirect
(localized-temporary-redirect)
(localized-temporary-redirect req)
(localized-temporary-redirect url)
(localized-temporary-redirect req url)
(localized-temporary-redirect req name-or-path)
(localized-temporary-redirect req name-or-path path-params)
(localized-temporary-redirect req name-or-path path-params query-params)
(localized-temporary-redirect req name-or-path lang)
(localized-temporary-redirect req name-or-path lang path-params)
(localized-temporary-redirect req name-or-path lang path-params query-params)
(localized-temporary-redirect req name-or-path lang path-params query-params & more)
Uses the localized-page
function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str
key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil
.
lock-wait
(lock-wait auth-config-or-lock-wait)
Returns lock-wait configuration option taken from the authentication configuration map or given as a time duration. Does not connect to a database.
login-auth-state
(login-auth-state req)
(login-auth-state req ring-match)
(login-auth-state req login-page-data auth-page-data)
(login-auth-state req ring-match login-page-data auth-page-data)
Helper which returns 2-element vector telling if the current (or given as a match) page is a login page (1st element) and/or an auth page (2nd element).
login-page
(login-page req)
(login-page req lang-id)
Returns a path for the login page. The page must have ID of :user/login
.
login-page?
(login-page? req)
(login-page? req ring-match)
Returns true if the current (or given as a match) page is a login page (has :login-page?
route data set to a truthy value).
move-to
(move-to)
(move-to req)
(move-to url)
(move-to req url)
(move-to req name-or-path)
(move-to req name-or-path path-params)
(move-to req name-or-path path-params query-params)
(move-to req name-or-path lang)
(move-to req name-or-path lang path-params)
(move-to req name-or-path lang path-params query-params)
(move-to req name-or-path lang path-params query-params & more)
Uses the localized-page
function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str
key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil
.
on-page?
(on-page?)
(on-page? req)
(on-page? req page-id-or-path)
(on-page? req page-id-or-path & more)
Checks if a current page matches the given route name (if an identifier is given) or the exact path. For multiple page names or paths, it returns true when any of them matches.
oplog
(oplog req-or-match & message)
Logs operation using operations logger. First argument should be a request map or a Match
object containing configuration associated with the current route data under the :oplog/config
key.
oplog-config
(oplog-config req-or-match)
Returns operations logger configuration obtained from a request or a Match
object.
oplog-logger
(oplog-logger req-or-match)
Retrieves operations logger function from a current route data (via :oplog/config
key and then the :fn/reporter
key), and if that fails, tries to retrieve it using :oplog/config
key of the request map (and :fn/reporter
sub-key). When everything fails it will fall back to a global variable amelinium.common.oplog.auth/log
. The given argument can be either a request map or a Match
object.
oplog-logger-populated
(oplog-logger-populated req)
(oplog-logger-populated req route-data)
Creates operations logging function on a basis of operations logger retrieved by getting :oplog/logger
key of the request (req
), and if that fails by calling oplog-logger-from-route-data
(when route-data
is given), and if that fails by calling oplog-logger
function on a req
(which falls back to amelinium.common.oplog.auth/log
).
page
(page req)
(page req name-or-path)
(page req name-or-path path-params)
(page req name-or-path path-params query-params)
(page req name-or-path lang)
(page req name-or-path lang path-params)
(page req name-or-path lang path-params query-params)
(page req name-or-path lang lang-required?)
(page req name-or-path lang path-params lang-required?)
(page req name-or-path lang path-params query-params lang-required?)
(page req name-or-path lang path-params query-params lang-required? name-path-fallback?)
(page _ _ name-or-path path-params query-params router hint-lang lang-settings-or-param)
(page _ name-or-path lang path-params query-params lang-required? name-path-fallback? router lang-settings-or-param)
Generates a page path for the given page identifier (a route name) or a path, and optional language identifier. When called with just a request map, returns a path of the current page.
It tries to be optimistic. When called for a page identified by its name (expressed as an identifier, usually a keyword) and with a language parameter to be found (so it cannot be looked up using just a name alone), it will use currently detected language obtained from the given request map (key :language/str
), and will use it.
Additional query parameters (query-params
) can be given. They will be used when generating path with localized-page
. If the path was given and it already contains query parameters, they will be replaced.
Additional path parameters (path-params
) may be given. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params
when matching by path causes them to be silently ignored.
When invoked with a language parameter, calls localized-page
internally.
When invoked with a language parameter, the lang-required?
argument may be used (by default set to false
) to check if a matching route is parameterized with a language parameter. This is to ensure that only a localized route is used.
When invoked with a language parameter, the optional name-path-fallback?
argument may be used (set to true
by default) to cause non-matching route identifier to be retried by extracting its path and calling localized-page
function for that path expressed as a string.
If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params
).
When invoked with a language parameter, the lang-required?
is set to false
(default), and a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).
When invoked with a language parameter, the lang-required?
is set to false
(default), and a path is given but it does not require language parameter plus the name-path-fallback?
argument is set to :brute-force
, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id
defined, and the given path is /users/
with language set to :pl
, then it will match /users/pl
even though the parameter is not related to a language.
When invoked with a language parameter, the lang-required?
is set to true
, and a path is given but it does not require a language parameter, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires language parameter.
parameterized-page
(parameterized-page)
(parameterized-page req)
(parameterized-page req name-or-path)
(parameterized-page req name-or-path param param-value)
(parameterized-page req name-or-path param param-value path-params)
(parameterized-page req name-or-path param param-value path-params query-params)
(parameterized-page req name-or-path param param-value require-param?)
(parameterized-page req name-or-path param param-value path-params require-param?)
(parameterized-page req name-or-path param param-value path-params query-params require-param?)
(parameterized-page req name-or-path param param-value path-params query-params require-param? name-path-fallback?)
(parameterized-page _ name-or-path param param-value path-params query-params require-param? name-path-fallback? router)
Generates a path for the given page identifier (which may be a name expressed with an identifier, preferably a keyword, or a path expressed as a string) and a parameter with the given value.
Optional path parameters may be given. They will be used to match a page by name if it requires additional parameters to be present.
Examples:
(parameterized-page req)
(parameterized-page req :login-page)
(parameterized-page req :login-page :lang :pl)
(parameterized-page req :login-page :lang :pl {:client "wow-corp"})
(parameterized-page req "/login/page/")
(parameterized-page req "/login/page/" :lang :pl)
(parameterized-page req "/en/login/page/" :lang :pl)
When called with just a request map, returns a path of the current page if the page exists. When called with a page name or path, it returns a path if the page exists.
The optional name-path-fallback?
argument, when set to a truthy value (default is false
), causes non-matching route identifier to be retried by extracting its path and calling this function for that path given as a string.
The optional require-param?
argument (set to false
when not given) enables extra check eliminating pages which do not support the given parameter, yet would be matched. Example:
(parameterized-page req :login-page :lang :pl true)
will fail if there is no parameter :lang
handled by the route named :login-page
.
When the given path is already parameterized then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.
Additional path parameters (path-params
) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params
when matching by path causes them to be silently ignored.
Additional query parameters (query-params
) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.
If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params
).
When the require-param?
is set to false
(default) and a path is given but it does not require this parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).
When the require-param?
is set to false
(default) and a path is given but it does not require this parameter plus the name-path-fallback?
argument is set to :brute-force
, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id
defined, and the given path is /users/
with :lang
parameter set to :pl
, then it will match /users/pl
even though the parameter name is different.
When the require-param?
is set to true
and a path is given but it does not require this parameter, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires this parameter.
path
(path)
(path req)
(path req name-or-path)
(path req name-or-path lang)
(path req name-or-path lang params)
(path req name-or-path lang params query-params)
(path name-or-path lang params query-params router language-settings-or-param)
Creates a URL on a basis of route name or a path.
If a page found does not have a language parameter it is accepted too.
When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.
Additional path parameters (params
) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving params
when matching by path causes them to be silently ignored.
Additional query parameters (query-params
) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.
If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using params
).
When a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).
path-language
(path-language req)
(path-language req-or-match path-or-lang-settings)
(path-language req path router)
(path-language _ path router language-settings-or-param)
Returns a language string if the given path contains a language parameter. Otherwise it returns nil.
path-param
(path-param req-or-match param)
(path-param req path param)
(path-param _ path param router)
Returns a parameter if the given path contains it and it is set. Otherwise it returns nil.
path-params
(path-params req-or-match)
(path-params req path)
(path-params _ path router)
Returns a map of parameters if the given path contains it. Otherwise it returns nil.
path-template-with-param
(path-template-with-param match required-param)
(path-template-with-param match required-param short-circuit)
Returns a path template for the given match if the route supports the given parameter.
path-variants
(path-variants path lang-id)
(path-variants path lang suffix)
Generates a list of all possible language variants of a path.
remove-status
macro
(remove-status req)
Removes :response/status
from req
using clojure.core/dissoc
.
render
(render)
(render req)
(render req status)
Returns response body on a basis of a value associated with the :response/body
key of the req
.
If status
is given and :response/body
is a map, it adds the following associations to it: :status
(with a keyword describing status as value), :status/title
(with a string describing status translated using a detected language) and :status/description
(with a longer string explaining the status, based on a translation key created by adding “.full” to the original status key). If any key already exists in :response/body
, it will not be added.
If status
is given and the :response/body
does not exist in req
, it adds it and associates it with an empty, performing the calculations described above.
Additionally, if the body map contains :status/title
or :status/description
key and does not contain :lang
key, the :lang
key will be added with an associated value of :language/id
taken from a request map req
.
render-accepted
(render-accepted)
(render-accepted req)
Renders 202 response with possible body taken from a request map (under the :response/body
).
render-already-reported
(render-already-reported)
(render-already-reported req)
Renders 208 response with possible body taken from a request map (under the :response/body
).
render-bad-gateway
(render-bad-gateway)
(render-bad-gateway req)
Renders 502 response with possible body taken from a request map (under the :response/body
).
render-bad-params
(render-bad-params)
(render-bad-params req)
Renders 422 response with possible body taken from a request map (under the :response/body
).
render-bad-request
(render-bad-request)
(render-bad-request req)
Renders 400 response with possible body taken from a request map (under the :response/body
).
render-bandwidth-limit-exceeded
(render-bandwidth-limit-exceeded)
(render-bandwidth-limit-exceeded req)
Renders 509 response with possible body taken from a request map (under the :response/body
).
render-blocked-by-windows-parental-controls
(render-blocked-by-windows-parental-controls)
(render-blocked-by-windows-parental-controls req)
Renders 450 response with possible body taken from a request map (under the :response/body
).
render-conflict
(render-conflict)
(render-conflict req)
Renders 409 response with possible body taken from a request map (under the :response/body
).
render-continue
(render-continue)
(render-continue req)
(render-continue req & more)
Renders 100 response without a body.
render-created
(render-created)
(render-created req)
(render-created req name-or-path)
(render-created req name-or-path lang)
(render-created req name-or-path lang params)
(render-created req name-or-path lang params query-params)
(render-created req name-or-path lang params query-params & more)
Renders 201 response with a redirect (possibly localized if a destination path is language-parameterized) and possible body taken from a request map (under the :response/body
). If a name or a path is not given as name-or-path
, it is looked up in req
under the :response/location
key.
render-early-hints
(render-early-hints)
(render-early-hints req)
Renders 103 response with possible body taken from a request map (under the :response/body
).
render-enhance-your-calm
(render-enhance-your-calm)
(render-enhance-your-calm req)
Renders 420 response with possible body taken from a request map (under the :response/body
).
render-error
(render-error)
(render-error req)
(render-error req sub-status)
(render-error req sub-statuses)
(render-error req sub-status default)
(render-error req sub-statuses default)
(render-error req sub-status default & more)
(render-error req sub-statuses default & more)
Renders an error response for the given request map and optional sub-status
(a keyword, mapped to a response rendering function, using a map passed under the :errors/config
key in a route data). If it is not given (or its value is nil
or false
) then render-internal-server-error
will be used to generate the response.
The resulting response body will have the :status
key set by the rendering function and :sub-status
added by this function. Additionally, :status/title
, :status/description
, :sub-status/title
and :sub-status/description
will be populated by strings explaining the status and sub-status.
Example:
(render-error req :verify/bad-token)
Will create a response with the following body:
{:status :error/unauthorized
:status/title "Unauthorized"
:status/description "You are not authorized to perform this action."
:sub-status :verify/bad-token
:sub-status/title "Bad token"
:sub-status/description "The given token is malformed of has expired."
:lang :en}
render-expectation-failed
(render-expectation-failed)
(render-expectation-failed req)
Renders 417 response with possible body taken from a request map (under the :response/body
).
render-failed-dependency
(render-failed-dependency)
(render-failed-dependency req)
Renders 424 response with possible body taken from a request map (under the :response/body
).
render-forbidden
(render-forbidden)
(render-forbidden req)
Renders 403 response with possible body taken from a request map (under the :response/body
).
render-found
(render-found)
(render-found req)
Renders 200 response with possible body taken from a request map (under the :response/body
).
render-gateway-timeout
(render-gateway-timeout)
(render-gateway-timeout req)
Renders 504 response with possible body taken from a request map (under the :response/body
).
render-gone
(render-gone)
(render-gone req)
Renders 410 response with possible body taken from a request map (under the :response/body
).
render-http-version-not-supported
(render-http-version-not-supported)
(render-http-version-not-supported req)
Renders 505 response with possible body taken from a request map (under the :response/body
).
render-im-a-teapot
(render-im-a-teapot)
(render-im-a-teapot req)
Renders 418 response with possible body taken from a request map (under the :response/body
).
render-im-used
(render-im-used)
(render-im-used req)
Renders 226 response with possible body taken from a request map (under the :response/body
).
render-in-progress
(render-in-progress)
(render-in-progress req)
Renders 202 response with possible body taken from a request map (under the :response/body
).
render-insufficient-storage
(render-insufficient-storage)
(render-insufficient-storage req)
Renders 507 response with possible body taken from a request map (under the :response/body
).
render-internal-server-error
(render-internal-server-error)
(render-internal-server-error req)
Renders 500 response with possible body taken from a request map (under the :response/body
).
render-length-required
(render-length-required)
(render-length-required req)
Renders 411 response with possible body taken from a request map (under the :response/body
).
render-localized-created
(render-localized-created)
(render-localized-created req)
(render-localized-created req name-or-path)
(render-localized-created req name-or-path lang)
(render-localized-created req name-or-path lang params)
(render-localized-created req name-or-path lang params query-params)
(render-localized-created req name-or-path lang params query-params & more)
Renders 201 response with a localized redirect and possible body taken from a request map (under the :response/body
). If a name or a path is not given as name-or-path
, it is looked up in req
under the :response/location
key.
render-locked
(render-locked)
(render-locked req)
Renders 423 response with possible body taken from a request map (under the :response/body
).
render-loop-detected
(render-loop-detected)
(render-loop-detected req)
Renders 508 response with possible body taken from a request map (under the :response/body
).
render-method-not-allowed
(render-method-not-allowed)
(render-method-not-allowed req)
Renders 405 response with possible body taken from a request map (under the :response/body
).
render-misdirected-request
(render-misdirected-request)
(render-misdirected-request req)
Renders 421 response with possible body taken from a request map (under the :response/body
).
render-multi-status
(render-multi-status)
(render-multi-status req)
Renders 207 response with possible body taken from a request map (under the :response/body
).
render-network-authentication-required
(render-network-authentication-required)
(render-network-authentication-required req)
Renders 511 response with possible body taken from a request map (under the :response/body
).
render-network-connect-timeout
(render-network-connect-timeout)
(render-network-connect-timeout req)
Renders 599 response with possible body taken from a request map (under the :response/body
).
render-network-read-timeout
(render-network-read-timeout)
(render-network-read-timeout req)
Renders 598 response with possible body taken from a request map (under the :response/body
).
render-no-content
(render-no-content)
(render-no-content req)
(render-no-content req & more)
Renders 204 response without a body.
render-non-authoritative-information
(render-non-authoritative-information)
(render-non-authoritative-information req)
Renders 203 response with possible body taken from a request map (under the :response/body
).
render-not-acceptable
(render-not-acceptable)
(render-not-acceptable req)
Renders 406 response with possible body taken from a request map (under the :response/body
).
render-not-extended
(render-not-extended)
(render-not-extended req)
Renders 510 response with possible body taken from a request map (under the :response/body
).
render-not-found
(render-not-found)
(render-not-found req)
Renders 404 response with possible body taken from a request map (under the :response/body
).
render-not-implemented
(render-not-implemented)
(render-not-implemented req)
Renders 501 response with possible body taken from a request map (under the :response/body
).
render-ok
(render-ok)
(render-ok req)
Renders 200 response with possible body taken from a request map (under the :response/body
).
render-page
(render-page)
(render-page req)
Renders 200 response with possible body taken from a request map (under the :response/body
).
render-partial-content
(render-partial-content)
(render-partial-content req)
Renders 206 response with possible body taken from a request map (under the :response/body
).
render-payment-required
(render-payment-required)
(render-payment-required req)
Renders 402 response with possible body taken from a request map (under the :response/body
).
render-precondition-failed
(render-precondition-failed)
(render-precondition-failed req)
Renders 412 response with possible body taken from a request map (under the :response/body
).
render-precondition-required
(render-precondition-required)
(render-precondition-required req)
Renders 428 response with possible body taken from a request map (under the :response/body
).
render-processing
(render-processing)
(render-processing req)
(render-processing req & more)
Renders 102 response without a body.
render-proxy-authentication-required
(render-proxy-authentication-required)
(render-proxy-authentication-required req)
Renders 407 response with possible body taken from a request map (under the :response/body
).
render-request-entity-too-large
(render-request-entity-too-large)
(render-request-entity-too-large req)
Renders 413 response with possible body taken from a request map (under the :response/body
).
render-request-header-fields-too-large
(render-request-header-fields-too-large)
(render-request-header-fields-too-large req)
Renders 431 response with possible body taken from a request map (under the :response/body
).
render-request-timeout
(render-request-timeout)
(render-request-timeout req)
Renders 408 response with possible body taken from a request map (under the :response/body
).
render-request-uri-too-long
(render-request-uri-too-long)
(render-request-uri-too-long req)
Renders 414 response with possible body taken from a request map (under the :response/body
).
render-requested-range-not-satisfiable
(render-requested-range-not-satisfiable)
(render-requested-range-not-satisfiable req)
Renders 416 response with possible body taken from a request map (under the :response/body
).
render-reset-content
(render-reset-content)
(render-reset-content req)
(render-reset-content req & more)
Renders 205 response without a body.
render-response
(render-response)
(render-response resp-fn)
(render-response resp-fn req)
(render-response resp-fn status req)
API response renderer. Uses the render
function to render the response body (unless the req
is already a valid response - in such case it is returned as-is) and resp-fn
function to construct the response map.
If status
is given and :response/body
is a map, it adds two associations to it: :status
(with a keyword describing HTTP status as value) and :message
(with a string describing HTTP status translated using a detected language). If any key already exists in :response/body
, it will not be added.
Additionally, if the body map contains :message
or message/sub
key and does not contain :lang
key, it will be added with a value of :language/id
taken from a request map req
.
render-response-force
(render-response-force)
(render-response-force resp-fn)
(render-response-force resp-fn req)
(render-response-force resp-fn status req)
API response renderer. Uses the render
function to render the response body and resp-fn
function to construct the response map.
If status
is given and :response/body
is a map, it adds two associations to it: :status
(with a keyword describing HTTP status as value) and :message
(with a string describing HTTP status translated using a detected language). If any key already exists in :response/body
, it will not be added.
Additionally, if the body map contains :message
or message/sub
key and does not contain :lang
key, it will be added with a value of :language/id
taken from a request map req
.
render-retry-with
(render-retry-with)
(render-retry-with req)
Renders 449 response with possible body taken from a request map (under the :response/body
).
render-status
(render-status)
(render-status req)
(render-status req sub-status)
(render-status req sub-statuses)
(render-status req sub-status default)
(render-status req sub-statuses default)
(render-status req sub-status default & more)
(render-status req sub-statuses default & more)
Renders a status response for the given request map and optional sub-status
(a keyword, mapped to a response rendering function, using a map passed under the :errors/config
key in a route data). If it is not given (or its value is nil
or false
) then render-ok
will be used to generate the response.
The resulting response body will have the :status
key set by the rendering function and :sub-status
added by this function. Additionally, :status/title
, :status/description
, :sub-status/title
and :sub-status/description
will be populated by strings explaining the status and sub-status.
Example:
(render-status req :verify/bad-token)
Will create a response with the following body:
{:status :error/unauthorized
:status/title "Unauthorized"
:status/description "You are not authorized to perform this action."
:sub-status :verify/bad-token
:sub-status/title "Bad token"
:sub-status/description "The given token is malformed of has expired."
:lang :en}
render-switching-protocols
(render-switching-protocols)
(render-switching-protocols req)
(render-switching-protocols req & more)
Renders 101 response without a body.
render-too-early
(render-too-early)
(render-too-early req)
Renders 425 response with possible body taken from a request map (under the :response/body
).
render-too-many-requests
(render-too-many-requests)
(render-too-many-requests req)
Renders 429 response with possible body taken from a request map (under the :response/body
).
render-unauthorized
(render-unauthorized)
(render-unauthorized req)
Renders 401 response with possible body taken from a request map (under the :response/body
).
render-unordered-collection
(render-unordered-collection)
(render-unordered-collection req)
Renders 425 response with possible body taken from a request map (under the :response/body
).
render-unprocessable-entity
(render-unprocessable-entity)
(render-unprocessable-entity req)
Renders 422 response with possible body taken from a request map (under the :response/body
).
render-unsupported-media-type
(render-unsupported-media-type)
(render-unsupported-media-type req)
Renders 415 response with possible body taken from a request map (under the :response/body
).
render-upgrade-required
(render-upgrade-required)
(render-upgrade-required req)
Renders 426 response with possible body taken from a request map (under the :response/body
).
render-variant-also-negotiates
(render-variant-also-negotiates)
(render-variant-also-negotiates req)
Renders 506 response with possible body taken from a request map (under the :response/body
).
response
macro
(response req & code)
Creates a response block. If the given req
is already a response then it is simply returned. Otherwise the expressions from code
are evaluated.
roles-for-context
(roles-for-context req user-id context)
(roles-for-context req context)
(roles-for-context req)
roles-tabler
(roles-tabler req)
(roles-tabler {{:keys [global-context], :or {global-context :!}} :roles/config, :as req} {:keys [user-id effective? include-global? include-self? present-label missing-label global-label global-marker global-present-label context-label contexts-labeler], :or {present-label "YES", missing-label "—", global-label "global", context-label "Context", contexts-labeler default-contexts-labeler, include-global? (not effective?), include-self? false}, :as opts})
router-match?
(router-match? v)
Returns true if the given argument is Reitit’s Match object.
see-other
(see-other)
(see-other req)
(see-other url)
(see-other req url)
(see-other req name-or-path)
(see-other req name-or-path path-params)
(see-other req name-or-path path-params query-params)
(see-other req name-or-path lang)
(see-other req name-or-path lang path-params)
(see-other req name-or-path lang path-params query-params)
(see-other req name-or-path lang path-params query-params & more)
Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
session-status
(session-status smap)
Returns session status for the given session map smap
.
slash-redir
(slash-redir req)
Redirects to a slash-trailed version of the same URI. If the URI already has a slash, it returns a req.
soft-lock-passed
(soft-lock-passed user time)
Returns the time duration between soft lock and the given moment. If the duration is zero or negative, it returns nil.
soft-lock-remains
(soft-lock-remains lock-passed auth-config-or-lw)
(soft-lock-remains user auth-config-or-lw time)
Returns the amount of time left before reaching lock-wait. If the amount is negative or zero, it returns nil. Does not connect to a database.
soft-lock-time
(soft-lock-time user)
Gets a soft lock time for the given user specified by a map having :soft-locked key.
soft-locked?
(soft-locked? lock-passed auth-config-or-lw)
(soft-locked? user auth-config-or-lw time)
Returns true if the given user account is soft-locked (the time amount which passed from the lock till the given time is lesser than the soft lock wait configuration option). Does not connect to a database.
split-query-params
(split-query-params path)
Splits path into 3 string components: path, location and query params. Returns a vector.
split-query-params-simple
(split-query-params-simple path)
Splits path into 2 components: path string and location / query params string. Returns a sequence.
strictly-localized-page
(strictly-localized-page req)
(strictly-localized-page req name-or-path)
(strictly-localized-page req name-or-path lang)
(strictly-localized-page req name-or-path lang params)
(strictly-localized-page req name-or-path lang params query-params)
(strictly-localized-page name-or-path lang params query-params router lang-param)
Same as localized-page
with lang-required?
always set to true
, name-path-fallback?
set to false
, and with less arities supported. When the language version of a page identified by its name is not present it will return nil
.
template-path
(template-path match params)
(template-path match params query-params)
(template-path path template params _)
Replaces parameters in the given path using a template.
temporary-redirect
(temporary-redirect)
(temporary-redirect req)
(temporary-redirect url)
(temporary-redirect req url)
(temporary-redirect req name-or-path)
(temporary-redirect req name-or-path path-params)
(temporary-redirect req name-or-path path-params query-params)
(temporary-redirect req name-or-path lang)
(temporary-redirect req name-or-path lang path-params)
(temporary-redirect req name-or-path lang path-params query-params)
(temporary-redirect req name-or-path lang path-params query-params & more)
Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect
. If the language is given it uses the localized-page
function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str
).
update-body
(update-body req)
(update-body req f)
(update-body req f a)
(update-body req f a b)
(update-body req f a b c)
(update-body req f a b c d)
(update-body req f a b c d & more)
Updates the :response/body
in a request map req
with a result of calling the function f
on the previous value and optional arguments. Uses io.randomseed.utils.map/qassoc
. Returns updated req
with a map under :response/body
key.