View Source Solicit.Response (solicit v1.3.2)
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()
@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()
@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.
@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()
@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()
@spec internal_server_error(Plug.Conn.t()) :: Plug.Conn.t()
@spec internal_server_error(Plug.Conn.t(), binary() | list()) :: Plug.Conn.t()
Signifies an internal_server_error request.
@spec method_not_allowed(Plug.Conn.t()) :: Plug.Conn.t()
@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.
@spec ok( Plug.Conn.t(), term(), term() ) :: Plug.Conn.t()
Returns a successful response.
@spec request_entity_too_large(Plug.Conn.t()) :: Plug.Conn.t()
Signifies a request_entity_too_large response.
@spec request_entity_too_large(Plug.Conn.t(), binary()) :: Plug.Conn.t()
@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.
@spec too_many_requests(Plug.Conn.t(), binary()) :: Plug.Conn.t()
@spec unauthorized(Plug.Conn.t()) :: Plug.Conn.t()
@spec unauthorized(Plug.Conn.t(), list()) :: Plug.Conn.t()
Signifies an unauthorized request.
@spec unprocessable_entity(Plug.Conn.t()) :: Plug.Conn.t()
@spec unprocessable_entity( Plug.Conn.t(), Ecto.Changeset.t() | binary() | atom() | Postgrex.Error.t() | list() ) :: Plug.Conn.t()
Signifies an unprocessable_entity response.
@spec unsupported_media_type(Plug.Conn.t()) :: Plug.Conn.t()
Signifies a unsupported_media_type response.
@spec unsupported_media_type(Plug.Conn.t(), binary()) :: Plug.Conn.t()