ja_resource v0.3.1 JaResource.Plug
Implements a plug that dispatches Phoenix actions to JaResource action behaviours.
You can optionally whitelist or blacklist the actions JaResource will respond to. Any actions outside of the standard index, show, create, update, and delete are always ignored and dispatched by Phoenix as usual. Any non-whitelisted or blacklisted actions are likewize passed to Phoenix as usual.
For example:
defmodule MyApp.V1.ArticleController do
use MyApp.Web, :controller
use JaResource
plug JaResource, except: [:delete]
# same as:
# plug JaResource, only: [:index, :show, :create, :update]
# Standard Phoenix Delete
def delete(conn, params) do
# Custom delete logic
end
# Non restful action
def publish(conn, params) do
# Custom publish logic
end
end
When dispatching an action you must have implemented the action behaviours
callbacks. This is typically done with use JaResource
and customized.
Alternatively you can use the individual actions, such as
use JaResource.Create
. You can even include just the behaviour and define
all the callbacks yourself via @behaviour JaResource.Create
.
See the action behaviours to learn how to customize each action.