hex_http behaviour (hex_core v0.21.1)

View Source

HTTP contract.

Summary

Functions

The error parameter of the first Bearer challenge that has one in a response's www-authenticate header (RFC 6750 section 3), or undefined when there is none.

Types

adapter_config/0

-type adapter_config() :: map().

body/0

-type body() :: {ContentType :: binary(), Body :: binary()} | undefined.

headers/0

-type headers() :: #{binary() => binary()}.

method/0

-type method() :: get | post | put | patch | delete.

status/0

-type status() :: non_neg_integer().

Callbacks

request/5

-callback request(method(), URI :: binary(), headers(), body(), adapter_config()) ->
                     {ok, {status(), headers(), binary()}} | {error, term()}.

request_to_file/6

-callback request_to_file(method(), URI :: binary(), headers(), body(), file:name_all(), adapter_config()) ->
                             {ok, {status(), headers()}} | {error, term()}.

Functions

bearer_error(Headers)

-spec bearer_error(headers()) -> binary() | undefined.

The error parameter of the first Bearer challenge that has one in a response's www-authenticate header (RFC 6750 section 3), or undefined when there is none.

The header is read the way RFC 9110 section 11.6.1 defines it: it can hold several challenges, a scheme can be followed by a token68 or by parameters, scheme and parameter names are case-insensitive, and a parameter value is a token or a quoted string.

request(Config, Method, URI, Headers, Body)

-spec request(hex_core:config(), method(), URI :: binary(), headers(), body()) ->
                 {ok, {status(), headers(), binary()}} | {error, term()}.

request_to_file(Config, Method, URI, Headers, Body, Filename)

-spec request_to_file(hex_core:config(), method(), URI :: binary(), headers(), body(), file:name_all()) ->
                         {ok, {status(), headers()}} | {error, term()}.