View Source PhxJsonRpc.Router.Middleware behaviour (Phoenix JSON RPC v0.5.0)
Middleware interface for the group of routes.
Request must have :valid => true
for passing through the next middleware.
example
Example
defmodule AuthMiddleware do
use PhxJsonRpc.Router.Middleware
@impl true
def handle(request, context) do
if context.meta_data.is_authenticated
request
else
request
|> Map.put(:valid?, false)
|> Map.put(:error, %AuthError{})
end
end
end
defmodule AuthError do
use PhxJsonRpc.Error,
message: "Unauthenticated",
code: -32_000
end
Link to this section Summary
Callbacks
Handles request before it will be dispatched to the controller.
Link to this section Callbacks
@callback handle( request :: PhxJsonRpc.Request.t(), context :: PhxJsonRpc.Router.Context.t() ) :: PhxJsonRpc.Request.t()
Handles request before it will be dispatched to the controller.