View Source Solicit.Response (solicit v1.3.1)

Standardized responses

Link to this section Summary

Functions

Returns a successful accepted response. Normally used to signify that the request was accepted, but might not have finished processing.

Returns structs or maps with specific fields extracted.

Signifies a bad gateway request.

Signifies a bad request.

Signifies a conflicting response.

Returns a successful created response.

Signifies a forbidden response.

Signifies a gone response.

Signifies an internal_server_error request.

Signifies a method not allowed response.

Returns a successful no_content response. Normally used when deleting.

Signifies a not found response.

Returns a successful response with no payload.

Returns a successful response.

Signifies a request_entity_too_large response.

Signifies a service unavailable request.

Signifies a request timeout response.

Signifies an too_many_requests request.

Signifies an unauthorized request.

Signifies an unprocessable_entity response.

Signifies a unsupported_media_type response.

Link to this section Functions

@spec accepted(Plug.Conn.t()) :: Plug.Conn.t()

Returns a successful accepted response. Normally used to signify that the request was accepted, but might not have finished processing.

@spec accepted(Plug.Conn.t(), any()) :: Plug.Conn.t()
Link to this function

accepted(conn, details, fields \\ nil)

View Source
@spec accepted(Plug.Conn.t(), term(), term()) :: Plug.Conn.t()

Returns structs or maps with specific fields extracted.

example

Example

def show(%{assigns: %{user: user}} = conn, _params) do
  conn
  |> as_json(user, [
    :id,
    :first_name,
    :last_name,
    :email
  ])
end

example-w-association

Example w/ Association

def show(%{assigns: %{unit: unit}} = conn, _params) do
  conn
  |> as_json(unit, [
    :id,
    :marketing_name,
    :street_address_1,
    :street_address_2,
    :city,
    :state,
    full_address: fn unit ->
      "#{unit.street_address_1}, #{unit.city}, #{unit.state}"
    end
    group: [
      :id,
      :marketing_name
    ],
    residents: [
      :id,
      :first_name,
      :last_name
    ]
  ])
end

If you don't add an associations fields and just the key :group, it will throw an ArgumentError letting you know that you forgot to add the related fields.

Note: Associations must be added last in the list or you will result in a syntax error

incorrect

Incorrect:

def show(%{assigns: %{unit: unit}} = conn, _params) do
  conn
  |> as_json(unit, [
    :id,
    :marketing_name,
    :street_address_1,
    :street_address_2,
    group: [
      :id,
      :marketing_name
    ],
    :city,
    :state
  ])
end

correct

Correct:

def show(%{assigns: %{unit: unit}} = conn, _params) do
  conn
  |> as_json(unit, [
    :id,
    :marketing_name,
    :street_address_1,
    :street_address_2,
    :city,
    :state,
    group: [
      :id,
      :marketing_name
    ],
  ])
end
@spec bad_gateway(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

bad_gateway(conn, message)

View Source
@spec bad_gateway(Plug.Conn.t(), binary() | [Solicit.ResponseError.t()]) ::
  Plug.Conn.t()

Signifies a bad gateway request.

@spec bad_request(Plug.Conn.t()) :: Plug.Conn.t()

Signifies a bad request.

Link to this function

bad_request(conn, changeset)

View Source
@spec bad_request(Plug.Conn.t(), Ecto.Changeset.t()) :: Plug.Conn.t()
@spec bad_request(Plug.Conn.t(), binary()) :: Plug.Conn.t()
@spec conflict(Plug.Conn.t()) :: Plug.Conn.t()

Signifies a conflicting response.

@spec conflict(Plug.Conn.t(), list() | binary()) :: Plug.Conn.t()
Link to this function

created(conn, result, fields \\ nil)

View Source
@spec created(Plug.Conn.t(), term(), term()) :: Plug.Conn.t()

Returns a successful created response.

@spec forbidden(Plug.Conn.t()) :: Plug.Conn.t()
@spec forbidden(Plug.Conn.t(), list()) :: Plug.Conn.t()

Signifies a forbidden response.

@spec gone(Plug.Conn.t()) :: Plug.Conn.t()

Signifies a gone response.

@spec gone(Plug.Conn.t(), binary()) :: Plug.Conn.t()
Link to this function

internal_server_error(conn)

View Source
@spec internal_server_error(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

internal_server_error(conn, message)

View Source
@spec internal_server_error(Plug.Conn.t(), binary() | list()) :: Plug.Conn.t()

Signifies an internal_server_error request.

Link to this function

method_not_allowed(conn)

View Source
@spec method_not_allowed(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

method_not_allowed(conn, errors)

View Source
@spec method_not_allowed(Plug.Conn.t(), list()) :: Plug.Conn.t()

Signifies a method not allowed response.

@spec no_content(Plug.Conn.t()) :: Plug.Conn.t()

Returns a successful no_content response. Normally used when deleting.

@spec not_found(Plug.Conn.t()) :: Plug.Conn.t()
@spec not_found(Plug.Conn.t(), list()) :: Plug.Conn.t()

Signifies a not found response.

@spec ok(Plug.Conn.t()) :: Plug.Conn.t()

Returns a successful response with no payload.

Link to this function

ok(conn, result, fields \\ nil)

View Source
@spec ok(
  Plug.Conn.t(),
  term(),
  term()
) :: Plug.Conn.t()

Returns a successful response.

Link to this function

request_entity_too_large(conn)

View Source
@spec request_entity_too_large(Plug.Conn.t()) :: Plug.Conn.t()

Signifies a request_entity_too_large response.

Link to this function

request_entity_too_large(conn, description)

View Source
@spec request_entity_too_large(Plug.Conn.t(), binary()) :: Plug.Conn.t()
Link to this function

service_unavailable(conn)

View Source
@spec service_unavailable(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

service_unavailable(conn, message)

View Source
@spec service_unavailable(Plug.Conn.t(), binary() | [Solicit.ResponseError.t()]) ::
  Plug.Conn.t()

Signifies a service unavailable request.

@spec timeout(Plug.Conn.t()) :: Plug.Conn.t()
@spec timeout(Plug.Conn.t(), list()) :: Plug.Conn.t()

Signifies a request timeout response.

@spec too_many_requests(Plug.Conn.t()) :: Plug.Conn.t()

Signifies an too_many_requests request.

Link to this function

too_many_requests(conn, message)

View Source
@spec too_many_requests(Plug.Conn.t(), binary()) :: Plug.Conn.t()
@spec unauthorized(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

unauthorized(conn, errors)

View Source
@spec unauthorized(Plug.Conn.t(), list()) :: Plug.Conn.t()

Signifies an unauthorized request.

Link to this function

unprocessable_entity(conn)

View Source
@spec unprocessable_entity(Plug.Conn.t()) :: Plug.Conn.t()
Link to this function

unprocessable_entity(conn, changeset)

View Source
@spec unprocessable_entity(
  Plug.Conn.t(),
  Ecto.Changeset.t() | binary() | atom() | Postgrex.Error.t() | list()
) :: Plug.Conn.t()

Signifies an unprocessable_entity response.

Link to this function

unsupported_media_type(conn)

View Source
@spec unsupported_media_type(Plug.Conn.t()) :: Plug.Conn.t()

Signifies a unsupported_media_type response.

Link to this function

unsupported_media_type(conn, description)

View Source
@spec unsupported_media_type(Plug.Conn.t(), binary()) :: Plug.Conn.t()