ja_resource v0.2.0 JaResource.Show behaviour

Defines a behaviour for displaying a resource and the function to execute it.

It relies on (and uses):

  • JaResource.Record
  • JaResource.Serializable

When used JaResource.Show defines the show/2 action suitable for handling json-api requests.

To customize the behaviour of the show action the following callbacks can be implemented:

  • handle_show/2
  • JaResource.Record.record/2
  • JaResource.Record.records/1

Summary

Functions

Execute the show action on a given module implementing Show behaviour and conn

Callbacks

Returns the model to be represented by this resource

Functions

call(controller, conn)

Execute the show action on a given module implementing Show behaviour and conn.

Callbacks

handle_show(arg0, arg1)

Specs

handle_show(Plug.Conn.t, JaResource.id) ::
  Plug.Conn.t |
  JaResource.record

Returns the model to be represented by this resource.

Default implementation is the result of the JaResource.Record.record/2 callback.

handle_show/2 can return nil to send a 404, a conn with any response/body, or a record to be serialized.

Example custom implementation:

def handle_show(conn, id) do
  Repo.get_by(Post, slug: id)
end

In most cases JaResource.Record.record/2 and JaResource.Records.records/1 are the better customization hooks.