Behaviours: gen_statem.
Authors: Federico Carrone (federico@inaka.net), Juan Facorro (juan@inaka.net).
body() = iodata() | body_chunked
connection() = pid()
connection_type() = http | https
event() = #{id => binary(), event => binary(), data => binary()}
headers() = #{term() => term()} | proplists:proplist()
http_verb() = get | post | head | delete | patch | put | options
open_opts() = #{transport_opts => [], timeout => timeout(), gun_opts => gun:opts()}
options() = #{async => boolean(), async_mode => binary | sse, handle_event => fun((fin | nofin, reference(), binary()) -> any()), timeout => timeout()}
Default 5000 ms
response() = #{status_code => integer(), header => map(), body => binary()}
result() = {ok, reference() | response()} | {error, term()}
uri() = iodata()
close/1 | Closes the connection with the host. |
data/2 | Send data when the. |
data/3 | |
delete/4 | Performs a DELETE request to Uri using
Headers . |
events/1 | Returns a list of all received events up to now. |
get/2 | Equivalent to get(Pid, Uri, #{}, #{}). |
get/3 | Equivalent to get(Pid, Uri, Headers, #{}). |
get/4 | Performs a GET request to Uri using
Headers . |
head/4 | Performs a HEAD request to Uri using
Headers . |
open/2 | Equivalent to get(Host, Port, http, #{}). |
open/3 | Equivalent to get(Host, Port, Type, #{}) or get(Host, Port, http, Opts). |
open/4 | Opens a connection of the type provided with the host and port specified and the specified connection timeout and/or Ranch transport options. |
options/4 | Performs a OPTIONS request to Uri using
Headers . |
parse_event/1 | Parse an SSE event in binary format. |
patch/4 | Performs a chunked PATCH request to Uri
using %% Headers as the content data. |
patch/5 | Performs a PATCH request to Uri using
Headers and Body as the content data. |
post/4 | Performs a chunked POST request to Uri
using %% Headers as the content data. |
post/5 | Performs a POST request to Uri using
Headers and Body as the content data. |
put/4 | Performs a chunked PUT request to Uri
using %% Headers as the content data. |
put/5 | Performs a PUT request to Uri using
Headers and Body as the content data. |
request/6 | Performs a request to Uri using the HTTP method
specified by Method , Body as the content data and
Headers as the request's headers. |
start/0 | Starts the application and all the ones it depends on. |
stop/0 | Stops the application. |
close(Pid::pid()) -> ok
Closes the connection with the host.
data(Conn::connection(), Data::body()) -> ok | {error, any()}
Send data when the
data(Conn::connection(), Data::body(), FinNoFin::fin | nofin) -> ok | {error, any()}
delete(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a DELETE request to Uri
using
Headers
.
events(Pid::pid()) -> [{nofin | fin, reference(), binary()}]
Returns a list of all received events up to now.
get(Pid::pid(), Uri::iodata()) -> result()
Equivalent to get(Pid, Uri, #{}, #{}).
Equivalent to get(Pid, Uri, Headers, #{}).
get(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a GET request to Uri
using
Headers
.
Available options are:
async
:
specifies if the request performed will return a chunked response.
It currently only works for GET requests. Default value is false.
async_mode
:
when async is true the mode specifies how the data received will be
processed. binary
mode treats eat chunk received as raw
binary. see
mode buffers each chunk, splitting the data
received into SSE. Default value is binary
.
handle_event
:
this function will be called each time either a chunk is received
(async_mode = binary
) or an event is parsed
(async_mode = sse
). If no handle_event function is provided
the data received is added to a queue, whose values can be obtained
calling the shotgun:events/1
. Default value is undefined.
head(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a HEAD request to Uri
using
Headers
.
open(Host::string(), Port::integer()) -> {ok, pid()} | {error, gun_open_failed | gun_open_timeout}
Equivalent to get(Host, Port, http, #{}).
open(Host::string(), Port::integer(), Type::connection_type()) -> {ok, pid()} | {error, gun_open_failed | gun_open_timeout}
open(Host::string(), Port::integer(), Opts::open_opts()) -> {ok, pid()} | {error, gun_open_failed | gun_open_timeout}
Equivalent to get(Host, Port, Type, #{}) or get(Host, Port, http, Opts).
open(Host::string(), Port::integer(), Type::connection_type(), Opts::open_opts()) -> {ok, pid()} | {ok, pid(), term()} | {error, already_present | {already_started, pid()} | gun_open_failed | gun_open_timeout}
Opens a connection of the type provided with the host and port specified and the specified connection timeout and/or Ranch transport options.
options(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a OPTIONS request to Uri
using
Headers
.
parse_event(EventBin::binary()) -> event()
Parse an SSE event in binary format. For example the following binary
<<"data: some content\n">>
will be turned into the
following map #{<<"data">> =>
<<"some content">>}
.
patch(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a chunked PATCH request to Uri
using %% Headers
as the content data.
patch(Pid::connection(), Uri::uri(), Headers::headers(), Body::body(), Options::options()) -> result()
Performs a PATCH request to Uri
using
Headers
and Body
as the content data.
post(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a chunked POST request to Uri
using %% Headers
as the content data.
post(Pid::connection(), Uri::uri(), Headers::headers(), Body::body(), Options::options()) -> result()
Performs a POST request to Uri
using
Headers
and Body
as the content data.
put(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()
Performs a chunked PUT request to Uri
using %% Headers
as the content data.
put(Pid::connection(), Uri::uri(), Headers::headers(), Body::body(), Options::options()) -> result()
Performs a PUT request to Uri
using
Headers
and Body
as the content data.
request(Pid::connection(), Method::http_verb(), Uri::uri(), Headers0::headers(), Body::body(), Options::options()) -> result()
Performs a request to Uri
using the HTTP method
specified by Method
, Body
as the content data and
Headers
as the request's headers.
start() -> {ok, [atom()]}
Starts the application and all the ones it depends on.
stop() -> ok | {error, term()}
Stops the application
Generated by EDoc