View Source ExTeal.Resource.Show behaviour (ExTeal v0.27.0)

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

It relies on (and uses):

  • ExTeal.Resource.Record
  • ExTeal.Resource.Serializable

When used ExTeal.Resource.Show defines the show/2 action suitable for handling api requests.

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

  • handle_show/2
  • render_show/2
  • ExTeal.Resource.Record.record/2
  • ExTeal.Resource.Record.records/1

Summary

Callbacks

Returns the model to be represented by this resource.

Returns a Plug.Conn in response to successful show.

Functions

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

Callbacks

@callback handle_show(Plug.Conn.t(), ExTeal.Resource.id()) ::
  Plug.Conn.t() | ExTeal.Resource.record()

Returns the model to be represented by this resource.

Default implementation is the result of the ExTeal.Resource.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 ExTeal.Resource.Record.record/2 and ExTeal.Resource.Records.records/1 are the better customization hooks.

Link to this callback

render_show(record, any, t)

View Source
@callback render_show(ExTeal.Resource.record(), any(), Plug.Conn.t()) :: Plug.Conn.t()

Returns a Plug.Conn in response to successful show.

Default implementation renders the view.

Functions

Link to this function

call(resource, conn, id)

View Source

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