AshJsonApi.Router (ash_json_api v1.4.30)
View SourceUse this module to create a router for your AshJsonApi.
To use this, create a module and do the following:
defmodule YourRouter do
use AshJsonApi.Router,
domains: [YourDomain, YourOtherDomain],
# these next two are optional, only add them if you want those endpoints
open_api: "/open_api",
json_schema: "/json_schema",
# tell us where it is mounted in your router
prefix: "/api/json"
end
Then in your Phoenix router or plug pipeline, forward to this plug. In phoenix, that looks like this:
forward "/api", YourRouter
Customizing request handling
You can provide the before_dispatch
option to customize request handling.
This can also be used to do things like set monitoring/observability information,
like which domain/resource/route is handling the request.
For example:
use AshJsonApi.Router,
...,
before_dispatch: {__MODULE__, :before_dispatch, []}
def before_dispatch(conn, route_info) do
...
end
route_info
will be one of the following:
:open_api
- The open api is being requested:json_schema
- The json schema is being requested:not_found
- No matching route was found- A map containing the keys:
domain
,resource
,route
,params