api_controller v0.2.0 ApiController behaviour

Summary

Macros

Defines a controller method with the given name

Macros

defmethod(name, schema, list)

Defines a controller method with the given name

Examples

defmethod :create, user_schema do
  name = request_params["name"]
  show_result(conn, name)
end

defp user_schema do
  [
    name: [required: true, type: :string],
    password: [required: true, type: :string, length: 8..32],
    type: [required: true, type: :string, inclusion: ["user", "admin"]]
    bio: [type: :string],
    age: [type: :integer]
  ]
end

Callbacks

show_error(arg0, arg1, arg2)

Specs

show_error(Plug.Conn.t, String.t, Keyword.t) :: Plug.Conn.t

Render JSON error and status.

Response example: {“status”: “error”, “reason”: “record_not_found”, errors: [], error_data: %{}}

show_error(arg0, arg1, arg2, arg3, arg4)

Specs

show_error(Plug.Conn.t, String.t, atom | non_neg_integer, [] | [String.t], %{} | map) :: Plug.Conn.t
show_result(arg0, term, arg2)

Specs

show_result(Plug.Conn.t, term, atom | non_neg_integer) :: Plug.Conn.t

Render JSON result and status.

Response example: {“status”: “ok”, “result”: “data”}