A liberator mixin to add HAL support to liberator.
In short:
application/hal+json as a supported media type.:handle-exception which logs the exception
when a logger implementing [[cartus.core/Logger]] is present on the
resource at :logger and responds with a HAL resource that does not
disclose details of the exception but does give it an ID for debugging
purposes.:handle-not-found, :handle-unauthorized, :handle-forbidden and
:handle-method-not-allowed.Depends on:
Optionally extends:
The JSON serialisation support for the application/hal+json media type uses
the same underlying JSON encoder as the
[[liberator.mixin.json.core|JSON mixin]]. If that mixin is configured with a
custom JSON encoder, all application/hal+json responses will use the custom
JSON encoder.
Resource supportThe halboy resource support
will add a :discovery link to any returned resource and expects a
:router supported by hype to be
available in the context, containing a route named
:discovery. The [[liberator.mixin.hypermedia.core|hypermedia mixin]] adds
a router to the context so nothing further is needed if that mixin is in
use.
A liberator mixin to add
[HAL](https://tools.ietf.org/html/draft-kelly-json-hal-00) support to
liberator.
In short:
- Adds `application/hal+json` as a supported media type.
- Adds support for JSON serialisation for maps and seqs for the HAL
media type.
- Adds support for [halboy](https://github.com/logicblocks/halboy)
resource serialisation.
- Adds a default handler for `:handle-exception` which logs the exception
when a logger implementing [[cartus.core/Logger]] is present on the
`resource` at `:logger` and responds with a HAL resource that does not
disclose details of the exception but does give it an ID for debugging
purposes.
- Adds default handlers responding with an empty HAL resource for
`:handle-not-found`, `:handle-unauthorized`, `:handle-forbidden` and
`:handle-method-not-allowed`.
- Adds a HAL error representation for use with the
[[liberator.mixin.validation.core|validation mixin]].
Depends on:
- the [[liberator.mixin.json.core|JSON mixin]],
- the [[liberator.mixin.hypermedia.core|hypermedia mixin]].
Optionally extends:
- the [[liberator.mixin.validation.core|validation mixin]].
### JSON serialisation support
The JSON serialisation support for the `application/hal+json` media type uses
the same underlying JSON encoder as the
[[liberator.mixin.json.core|JSON mixin]]. If that mixin is configured with a
custom JSON encoder, all `application/hal+json` responses will use the custom
JSON encoder.
### halboy `Resource` support
The [halboy](https://github.com/logicblocks/halboy) resource support
will add a `:discovery` link to any returned resource and expects a
`:router` supported by [hype](https://github.com/logicblocks/hype) to be
available in the `context`, containing a route named
`:discovery`. The [[liberator.mixin.hypermedia.core|hypermedia mixin]] adds
a router to the `context` so nothing further is needed if that mixin is in
use.(with-exception-handler)Returns a mixin which adds a generic exception handler, logging the exception and returning an error representation masking the exception.
This mixin expects a :logger to be present on the resource. If no :logger
is found, nothing will be logged.
Returns a mixin which adds a generic exception handler, logging the exception and returning an error representation masking the exception. This mixin expects a `:logger` to be present on the resource. If no `:logger` is found, nothing will be logged.
(with-hal-error-representation)Returns a mixin adding a HAL error representation factory function to the
resource, at :error-representation, for use by other mixins, such as
liberator.mixin.validation when they need to render errors.
The error representation factory function expects the context to include
a :self href, an :error-id and an :error-context used in the resulting
representation.
Returns a mixin adding a HAL error representation factory function to the resource, at `:error-representation`, for use by other mixins, such as `liberator.mixin.validation` when they need to render errors. The error representation factory function expects the context to include a `:self` href, an `:error-id` and an `:error-context` used in the resulting representation.
(with-hal-media-type)Returns a mixin to add the HAL media type to the available media types.
Returns a mixin to add the HAL media type to the available media types.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |