Relax.Resource.Delete behaviour

Include in your resource to respond to DELETE /:id

Typically brought into your resource via use Relax.Resource.

Update defines two callback behaviours, one of which (delete/2) must be implemented.

In addition this module includes the behaviours:

Summary

halt_not_found(model, conn)

Types

id :: integer | String.t

Functions

halt_not_found(model, conn)

Callbacks

delete/2

Specs:

  • delete(Plug.Conn.t, %{}) :: Plug.Conn.t | {atom, %{}} | %{}

Delete a record.

Receives the conn and the model as found by fetch_one/2.

def delete(_conn, post) do
  MyApp.Repo.delete!(post)
end

A conn may also be returned:

def delete(conn), do: halt send_resp(conn, 401, "nope")
delete_resource/2

Specs:

  • delete_resource(Plug.Conn.t, id) :: Plug.Conn.t

This callback can be used to completely override the delete action.

It accepts a Plug.Conn and must return a Plug.Conn.t