2016-01-14 13:35:25 +01:00
|
|
|
= cowboy_rest(3)
|
|
|
|
|
|
|
|
== Name
|
|
|
|
|
|
|
|
cowboy_rest - REST handlers
|
|
|
|
|
|
|
|
== Description
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
The `cowboy_rest` module implements REST semantics on top of
|
|
|
|
the HTTP protocol.
|
|
|
|
|
2014-09-30 20:12:13 +03:00
|
|
|
This module is a sub protocol that defines many callbacks
|
|
|
|
be implemented by handlers. The `init/2` and `terminate/3`
|
|
|
|
callbacks are common to all handler types and are documented
|
2016-01-14 13:35:25 +01:00
|
|
|
in the manual for the link:cowboy_handler.asciidoc[cowboy_handler] module.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2014-09-30 20:12:13 +03:00
|
|
|
All other callbacks are optional, though some may become
|
|
|
|
required depending on the return value of previous callbacks.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== Meta values
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
charset = binary()::
|
|
|
|
Negotiated charset.
|
|
|
|
+
|
|
|
|
This value may not be defined if no charset was negotiated.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
language = binary()::
|
|
|
|
Negotiated language.
|
|
|
|
+
|
|
|
|
This value may not be defined if no language was negotiated.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
media_type = {binary(), binary(), '*' | [{binary(), binary()}]}::
|
|
|
|
Negotiated media-type.
|
|
|
|
+
|
|
|
|
The media-type is the content-type, excluding the charset.
|
|
|
|
+
|
|
|
|
This value is always defined after the call to
|
|
|
|
`content_types_provided/2`.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== Terminate reasons
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2014-09-30 20:12:13 +03:00
|
|
|
The following values may be received as the terminate reason
|
|
|
|
in the optional `terminate/3` callback.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
normal::
|
|
|
|
The connection was closed normally.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{crash, Class, Reason}::
|
|
|
|
A crash occurred in the handler. `Class` and `Reason` can be
|
|
|
|
used to obtain more information about the crash. The function
|
|
|
|
`erlang:get_stacktrace/0` can also be called to obtain the
|
|
|
|
stacktrace of the process when the crash occurred.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== Callbacks
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== Callback(Req, State) -> {Value, Req, State} | {stop, Req, State}
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Callback:: One of the REST callbacks described below.
|
|
|
|
Req = cowboy_req:req():: The Req object.
|
|
|
|
State = any():: Handler state.
|
|
|
|
Value:: See the REST callbacks description below.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Please see the REST callbacks description below for details
|
|
|
|
on the `Value` type, the default value if the callback is
|
|
|
|
not defined, and more general information on when the
|
|
|
|
callback is called and what its intended use is.
|
|
|
|
|
2014-11-07 20:19:05 +02:00
|
|
|
The `stop` tuple can be returned to stop REST processing.
|
2014-07-06 13:10:35 +02:00
|
|
|
It is up to the resource code to send a reply before that,
|
|
|
|
otherwise a `204 No Content` will be sent.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
== REST callbacks description
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== allowed_methods
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: [binary()]
|
|
|
|
Default value:: `[<<"GET">>, <<"HEAD">>, <<"OPTIONS">>]`
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the list of allowed methods.
|
|
|
|
|
|
|
|
Methods are case sensitive. Standard methods are always uppercase.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== allow_missing_post
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: POST
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether POST is allowed when the resource doesn't exist.
|
|
|
|
|
|
|
|
Returning `true` here means that a new resource will be
|
|
|
|
created. The URL to the created resource should also be
|
|
|
|
returned from the `AcceptResource` callback.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== charsets_provided
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: [binary()]
|
|
|
|
Default behavior:: Skip to the next step if undefined.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the list of charsets the resource provides.
|
|
|
|
|
|
|
|
The list must be ordered in order of preference.
|
|
|
|
|
|
|
|
If the accept-charset header was not sent, the first charset
|
|
|
|
in the list will be selected. Otherwise Cowboy will select
|
|
|
|
the most appropriate charset from the list.
|
|
|
|
|
|
|
|
The chosen charset will be set in the `Req` object as the meta
|
|
|
|
value `charset`.
|
|
|
|
|
|
|
|
While charsets are case insensitive, this callback is expected
|
|
|
|
to return them as lowercase binary.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== content_types_accepted
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: POST, PUT, PATCH
|
|
|
|
Value type:: [{binary() | {Type, SubType, Params}, AcceptResource}]
|
|
|
|
Default behavior:: Crash if undefined.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
* Type = SubType = binary()
|
|
|
|
* Params = '*' | [{binary(), binary()}]
|
|
|
|
* AcceptResource = atom()
|
|
|
|
|
|
|
|
Return the list of content-types the resource accepts.
|
|
|
|
|
|
|
|
The list must be ordered in order of preference.
|
|
|
|
|
|
|
|
Each content-type can be given either as a binary string or as
|
|
|
|
a tuple containing the type, subtype and parameters.
|
|
|
|
|
|
|
|
Cowboy will select the most appropriate content-type from the list.
|
|
|
|
If any parameter is acceptable, then the tuple form should be used
|
|
|
|
with parameters set to `'*'`. If the parameters value is set to `[]`
|
|
|
|
only content-type values with no parameters will be accepted. All
|
|
|
|
parameter values are treated in a case sensitive manner except the
|
|
|
|
`charset` parameter, if present, which is case insensitive.
|
|
|
|
|
|
|
|
This function will be called for POST, PUT and PATCH requests.
|
|
|
|
It is entirely possible to define different callbacks for different
|
|
|
|
methods if the handling of the request differs. Simply verify
|
|
|
|
what the method is with `cowboy_req:method/1` and return a
|
|
|
|
different list for each methods.
|
|
|
|
|
|
|
|
The `AcceptResource` value is the name of the callback that will
|
|
|
|
be called if the content-type matches. It is defined as follow.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Value type:: true | {true, URL} | false
|
|
|
|
Default behavior:: Crash if undefined.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Process the request body.
|
|
|
|
|
|
|
|
This function should create or update the resource with the
|
|
|
|
information contained in the request body. This information
|
|
|
|
may be full or partial depending on the request method.
|
|
|
|
|
2014-07-10 14:27:11 +02:00
|
|
|
If the request body was processed successfully, `true` must
|
|
|
|
be returned. If the request method is POST, `{true, URL}` may
|
|
|
|
be returned instead, and Cowboy will redirect the client to
|
|
|
|
the location of the newly created resource.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
If a response body must be sent, the appropriate media-type, charset
|
|
|
|
and language can be retrieved using the `cowboy_req:meta/{2,3}`
|
|
|
|
functions. The respective keys are `media_type`, `charset`
|
|
|
|
and `language`. The body can be set using `cowboy_req:set_resp_body/2`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== content_types_provided
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: [{binary() | {Type, SubType, Params}, ProvideResource}]
|
|
|
|
Default value:: `[{{<<"text">>, <<"html">>, '*'}, to_html}]`
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
* Type = SubType = binary()
|
|
|
|
* Params = '*' | [{binary(), binary()}]
|
|
|
|
* ProvideResource = atom()
|
|
|
|
|
|
|
|
Return the list of content-types the resource provides.
|
|
|
|
|
|
|
|
The list must be ordered in order of preference.
|
|
|
|
|
|
|
|
Each content-type can be given either as a binary string or as
|
|
|
|
a tuple containing the type, subtype and parameters.
|
|
|
|
|
|
|
|
Cowboy will select the most appropriate content-type from the list.
|
|
|
|
If any parameter is acceptable, then the tuple form should be used
|
|
|
|
with parameters set to `'*'`. If the parameters value is set to `[]`
|
|
|
|
only content-type values with no parameters will be accepted. All
|
|
|
|
parameter values are treated in a case sensitive manner except the
|
|
|
|
`charset` parameter, if present, which is case insensitive.
|
|
|
|
|
|
|
|
The `ProvideResource` value is the name of the callback that will
|
|
|
|
be called if the content-type matches. It will only be called when
|
|
|
|
a representation of the resource needs to be returned. It is defined
|
|
|
|
as follow.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD
|
|
|
|
Value type:: iodata() | {stream, Fun} | {stream, Len, Fun} | {chunked, ChunkedFun}
|
|
|
|
Default behavior:: Crash if undefined.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the response body.
|
|
|
|
|
|
|
|
The response body may be provided directly or through a fun.
|
|
|
|
If a fun tuple is returned, the appropriate `set_resp_body_fun`
|
|
|
|
function will be called. Please refer to the documentation for
|
|
|
|
these functions for more information about the types.
|
|
|
|
|
|
|
|
The call to this callback happens a good time after the call to
|
|
|
|
`content_types_provided/2`, when it is time to start rendering
|
|
|
|
the response body.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== delete_completed
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: DELETE
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the delete action has been completed.
|
|
|
|
|
|
|
|
This function should return `false` if there is no guarantee
|
|
|
|
that the resource gets deleted immediately from the system,
|
|
|
|
including from any internal cache.
|
|
|
|
|
|
|
|
When this function returns `false`, a `202 Accepted`
|
|
|
|
response will be sent instead of a `200 OK` or `204 No Content`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== delete_resource
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: DELETE
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Delete the resource.
|
|
|
|
|
|
|
|
The value returned indicates if the action was successful,
|
|
|
|
regardless of whether the resource is immediately deleted
|
|
|
|
from the system.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== expires
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD
|
|
|
|
Value type:: calendar:datetime() | binary() | undefined
|
|
|
|
Default value:: undefined
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the date of expiration of the resource.
|
|
|
|
|
|
|
|
This date will be sent as the value of the expires header.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== forbidden
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether access to the resource is forbidden.
|
|
|
|
|
|
|
|
A `403 Forbidden` response will be sent if this
|
|
|
|
function returns `true`. This status code means that
|
|
|
|
access is forbidden regardless of authentication,
|
|
|
|
and that the request shouldn't be repeated.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== generate_etag
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: binary() | {weak | strong, binary()}
|
|
|
|
Default value:: undefined
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the entity tag of the resource.
|
|
|
|
|
|
|
|
This value will be sent as the value of the etag header.
|
|
|
|
|
|
|
|
If a binary is returned, then the value will be parsed
|
|
|
|
to the tuple form automatically. The value must be in
|
|
|
|
the same format as the etag header, including quotes.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== is_authorized
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: true | {false, AuthHeader}
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2015-07-27 23:58:58 +02:00
|
|
|
|
|
|
|
* AuthHead = iodata()
|
|
|
|
|
2014-07-06 13:10:35 +02:00
|
|
|
Return whether the user is authorized to perform the action.
|
|
|
|
|
|
|
|
This function should be used to perform any necessary
|
|
|
|
authentication of the user before attempting to perform
|
|
|
|
any action on the resource.
|
|
|
|
|
|
|
|
If the authentication fails, the value returned will be sent
|
|
|
|
as the value for the www-authenticate header in the
|
|
|
|
`401 Unauthorized` response.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== is_conflict
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: PUT
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the put action results in a conflict.
|
|
|
|
|
|
|
|
A `409 Conflict` response will be sent if this function
|
|
|
|
returns `true`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== known_methods
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: [binary()]
|
|
|
|
Default value:: `[<<"GET">>, <<"HEAD">>, <<"POST">>, <<"PUT">>, <<"PATCH">>, <<"DELETE">>, <<"OPTIONS">>]`
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the list of known methods.
|
|
|
|
|
|
|
|
The full list of methods known by the server should be
|
|
|
|
returned, regardless of their use in the resource.
|
|
|
|
|
|
|
|
The default value lists the methods Cowboy knows and
|
|
|
|
implement in `cowboy_rest`.
|
|
|
|
|
|
|
|
Methods are case sensitive. Standard methods are always uppercase.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== languages_provided
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: [binary()]
|
|
|
|
Default behavior:: Skip to the next step if undefined.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the list of languages the resource provides.
|
|
|
|
|
|
|
|
The list must be ordered in order of preference.
|
|
|
|
|
|
|
|
If the accept-language header was not sent, the first language
|
|
|
|
in the list will be selected. Otherwise Cowboy will select
|
|
|
|
the most appropriate language from the list.
|
|
|
|
|
|
|
|
The chosen language will be set in the `Req` object as the meta
|
|
|
|
value `language`.
|
|
|
|
|
|
|
|
While languages are case insensitive, this callback is expected
|
|
|
|
to return them as lowercase binary.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== last_modified
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: calendar:datetime()
|
|
|
|
Default value:: undefined
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the date of last modification of the resource.
|
|
|
|
|
|
|
|
This date will be used to test against the if-modified-since
|
|
|
|
and if-unmodified-since headers, and sent as the last-modified
|
|
|
|
header in the response of GET and HEAD requests.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== malformed_request
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the request is malformed.
|
|
|
|
|
|
|
|
Cowboy has already performed all the necessary checks
|
|
|
|
by the time this function is called, so few resources
|
|
|
|
are expected to implement it.
|
|
|
|
|
|
|
|
The check is to be done on the request itself, not on
|
|
|
|
the request body, which is processed later.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== moved_permanently
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: {true, URL} | false
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2015-07-27 23:58:58 +02:00
|
|
|
|
|
|
|
* URL = iodata()
|
|
|
|
|
2014-07-06 13:10:35 +02:00
|
|
|
Return whether the resource was permanently moved.
|
|
|
|
|
|
|
|
If it was, its new URL is also returned and sent in the
|
|
|
|
location header in the response.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== moved_temporarily
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PATCH, DELETE
|
|
|
|
Value type:: {true, URL} | false
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
With types:
|
2015-07-27 23:58:58 +02:00
|
|
|
|
|
|
|
* URL = iodata()
|
|
|
|
|
2014-07-06 13:10:35 +02:00
|
|
|
Return whether the resource was temporarily moved.
|
|
|
|
|
|
|
|
If it was, its new URL is also returned and sent in the
|
|
|
|
location header in the response.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== multiple_choices
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether there are multiple representations of the resource.
|
|
|
|
|
|
|
|
This function should be used to inform the client if there
|
|
|
|
are different representations of the resource, for example
|
|
|
|
different content-type. If this function returns `true`,
|
|
|
|
the response body should include information about these
|
|
|
|
different representations using `cowboy_req:set_resp_body/2`.
|
|
|
|
The content-type of the response should be the one previously
|
|
|
|
negociated and that can be obtained by calling
|
|
|
|
`cowboy_req:meta(media_type, Req)`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== options
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: OPTIONS
|
|
|
|
Value type:: ok
|
|
|
|
Default value:: ok
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Handle a request for information.
|
|
|
|
|
|
|
|
The response should inform the client the communication
|
|
|
|
options available for this resource.
|
|
|
|
|
|
|
|
By default, Cowboy will send a `200 OK` response with the
|
|
|
|
allow header set.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== previously_existed
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PATCH, DELETE
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the resource existed previously.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== resource_exists
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the resource exists.
|
|
|
|
|
|
|
|
If it exists, conditional headers will be tested before
|
|
|
|
attempting to perform the action. Otherwise, Cowboy will
|
|
|
|
check if the resource previously existed first.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== service_available
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the service is available.
|
|
|
|
|
|
|
|
This function can be used to test that all relevant backend
|
|
|
|
systems are up and able to handle requests.
|
|
|
|
|
|
|
|
A `503 Service Unavailable` response will be sent if this
|
|
|
|
function returns `false`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== uri_too_long
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: false
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the requested URI is too long.
|
|
|
|
|
|
|
|
Cowboy has already performed all the necessary checks
|
|
|
|
by the time this function is called, so few resources
|
|
|
|
are expected to implement it.
|
|
|
|
|
|
|
|
A `414 Request-URI Too Long` response will be sent if this
|
|
|
|
function returns `true`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== valid_content_headers
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the content-* headers are valid.
|
|
|
|
|
|
|
|
This also applies to the transfer-encoding header. This
|
|
|
|
function must return `false` for any unknown content-*
|
|
|
|
headers, or if the headers can't be understood. The
|
|
|
|
function `cowboy_req:parse_header/2` can be used to
|
|
|
|
quickly check the headers can be parsed.
|
|
|
|
|
|
|
|
A `501 Not Implemented` response will be sent if this
|
|
|
|
function returns `false`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== valid_entity_length
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: all
|
|
|
|
Value type:: boolean()
|
|
|
|
Default value:: true
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return whether the request body length is within acceptable boundaries.
|
|
|
|
|
|
|
|
A `413 Request Entity Too Large` response will be sent if this
|
|
|
|
function returns `false`.
|
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
=== variances
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
Methods:: GET, HEAD, POST, PUT, PATCH, DELETE
|
|
|
|
Value type:: [binary()]
|
|
|
|
Default value:: []
|
2014-07-06 13:10:35 +02:00
|
|
|
|
|
|
|
Return the list of headers that affect the representation of the resource.
|
|
|
|
|
|
|
|
These request headers return the same resource but with different
|
|
|
|
parameters, like another language or a different content-type.
|
|
|
|
|
|
|
|
Cowboy will automatically add the accept, accept-language and
|
|
|
|
accept-charset headers to the list if the respective functions
|
|
|
|
were defined in the resource.
|
|
|
|
|
|
|
|
This operation is performed right before the `resource_exists/2`
|
|
|
|
callback. All responses past that point will contain the vary
|
|
|
|
header which holds this list.
|