Packages

A behaviour for defining JSON-API spec controllers in Phoenix. Lets you focus on your data, not on boilerplate controller code. Like Webmachine for Phoenix.

Current section

Files

Jump to
ja_resource lib ja_resource.ex
Raw

lib/ja_resource.ex

defmodule JaResource do
@type record :: map() | Ecto.Schema.t
@type records :: module | Ecto.Query.t | list(record)
@type params :: map()
@type attributes :: map()
@type id :: String.t
@moduledoc """
When used, includes all restful actions behaviours. Also a plug.
Example usage in phoenix controller:
defmodule Example.ArticleController do
use Example.Web, :controller
use JaResource
plug JaResource, except: [:create]
end
See JaResource.Plug for plug options and documentation.
See the "action" behaviours for info on customizing each behaviour:
* JaResource.Index
* JaResource.Show
* JaResource.Create
* JaResource.Update
* JaResource.Delete
"""
defmacro __using__(_opts) do
quote do
use JaResource.Index
use JaResource.Show
use JaResource.Create
use JaResource.Update
use JaResource.Delete
end
end
@behavour Plug
defdelegate init(opts), to: JaResource.Plug
defdelegate call(conn, opts), to: JaResource.Plug
end