Module shotgun

Shotgun's main interface.

Behaviours: gen_statem.

Authors: Federico Carrone (federico@inaka.net), Juan Facorro (juan@inaka.net).

Description

Shotgun's main interface. Use the functions provided in this module to open a connection and make requests.

Data Types

body()

body() = iodata() | body_chunked

connection()

connection() = pid()

connection_type()

connection_type() = http | https

event()

event() = #{id => binary(), event => binary(), data => binary()}

headers()

headers() = #{term() => term()} | proplists:proplist()

http_verb()

http_verb() = get | post | head | delete | patch | put | options

open_opts()

open_opts() = #{transport_opts => [], timeout => timeout(), gun_opts => gun:opts()}

options()

options() = #{async => boolean(), async_mode => binary | sse, handle_event => fun((fin | nofin, reference(), binary()) -> any()), timeout => timeout()}

Default 5000 ms

response()

response() = #{status_code => integer(), header => map(), body => binary()}

result()

result() = {ok, reference() | response()} | {error, term()}

uri()

uri() = iodata()

Function Index

close/1Closes the connection with the host.
data/2Send data when the.
data/3
delete/4Performs a DELETE request to Uri using Headers.
events/1Returns a list of all received events up to now.
get/2Equivalent to get(Pid, Uri, #{}, #{}).
get/3Equivalent to get(Pid, Uri, Headers, #{}).
get/4Performs a GET request to Uri using Headers.
head/4Performs a HEAD request to Uri using Headers.
open/2Equivalent to get(Host, Port, http, #{}).
open/3Equivalent to get(Host, Port, Type, #{}) or get(Host, Port, http, Opts).
open/4Opens a connection of the type provided with the host and port specified and the specified connection timeout and/or Ranch transport options.
options/4Performs a OPTIONS request to Uri using Headers.
parse_event/1Parse an SSE event in binary format.
patch/4Performs a chunked PATCH request to Uri using %% Headers as the content data.
patch/5Performs a PATCH request to Uri using Headers and Body as the content data.
post/4Performs a chunked POST request to Uri using %% Headers as the content data.
post/5Performs a POST request to Uri using Headers and Body as the content data.
put/4Performs a chunked PUT request to Uri using %% Headers as the content data.
put/5Performs a PUT request to Uri using Headers and Body as the content data.
request/6Performs a request to Uri using the HTTP method specified by Method, Body as the content data and Headers as the request's headers.
start/0Starts the application and all the ones it depends on.
stop/0Stops the application.

Function Details

close/1

close(Pid::pid()) -> ok

Closes the connection with the host.

data/2

data(Conn::connection(), Data::body()) -> ok | {error, any()}

Send data when the

data/3

data(Conn::connection(), Data::body(), FinNoFin::fin | nofin) -> ok | {error, any()}

delete/4

delete(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a DELETE request to Uri using Headers.

events/1

events(Pid::pid()) -> [{nofin | fin, reference(), binary()}]

Returns a list of all received events up to now.

get/2

get(Pid::pid(), Uri::iodata()) -> result()

Equivalent to get(Pid, Uri, #{}, #{}).

get/3

get(Pid::pid(), Uri::iodata(), Headers::headers()) -> result()

Equivalent to get(Pid, Uri, Headers, #{}).

get/4

get(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a GET request to Uri using Headers. Available options are:

head/4

head(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a HEAD request to Uri using Headers.

open/2

open(Host::string(), Port::integer()) -> {ok, pid()} | {error, gun_open_failed | gun_open_timeout}

Equivalent to get(Host, Port, http, #{}).

open/3

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/4

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/4

options(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a OPTIONS request to Uri using Headers.

parse_event/1

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/4

patch(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a chunked PATCH request to Uri using %% Headers as the content data.

patch/5

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/4

post(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a chunked POST request to Uri using %% Headers as the content data.

post/5

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/4

put(Pid::connection(), Uri::uri(), Headers::headers(), Options::options()) -> result()

Performs a chunked PUT request to Uri using %% Headers as the content data.

put/5

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/6

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/0

start() -> {ok, [atom()]}

Starts the application and all the ones it depends on.

stop/0

stop() -> ok | {error, term()}

Stops the application


Generated by EDoc