z_fetch (zotonic_core v1.0.0-rc.17)

Fetch data from URLs. Interfaces to z_url_fetch and z_url_metadata.

Summary

Functions

Fetch data from an URL. Return the data as a data url.

Map (http) errors to readable format.

Fetch data from an URL. Let modules change the fetch options.

Perform a request and data from an URL. Let modules change the fetch options.

Fetch JSON data from an URL. Let modules change the fetch options. On success, the returned body is parsed with jsxrecord and returned.

Perform a request and fetch JSON data from an URL. Let modules change the fetch options. On success, the returned body is parsed with jsxrecord and returned.

Fetch data from an URL. Let modules change the fetch options.

Fetch the metadata from an URL. Let modules change the fetch options.

Functions

as_data_url(Url, Options, Context)

-spec as_data_url(string() | binary() | undefined, z_url_fetch:options(), z:context()) ->
                     {ok, binary()} | {error, term()}.

Fetch data from an URL. Return the data as a data url.

error_msg(S4xx, Context)

-spec error_msg(integer() | {error, term()}, z:context()) -> binary().

Map (http) errors to readable format.

fetch(Url, Options, Context)

-spec fetch(Url, Options, Context) -> z_url_fetch:fetch_result()
               when Url :: string() | binary(), Options :: z_url_fetch:options(), Context :: z:context().

Fetch data from an URL. Let modules change the fetch options.

fetch(Method, Url, Payload, Options, Context)

-spec fetch(Method, Url, Payload, Options, Context) -> Result
               when
                   Method :: get | post | delete | put | patch,
                   Url :: string() | binary(),
                   Payload :: list() | binary() | map(),
                   Options :: z_url_fetch:options(),
                   Context :: z:context(),
                   Result :: z_url_fetch:fetch_result().

Perform a request and data from an URL. Let modules change the fetch options.

fetch_json(Url, Options, Context)

-spec fetch_json(Url, Options, Context) -> {ok, JSON} | {error, term()}
                    when
                        Url :: string() | binary(),
                        Options :: z_url_fetch:options(),
                        Context :: z:context(),
                        JSON :: term().

Fetch JSON data from an URL. Let modules change the fetch options. On success, the returned body is parsed with jsxrecord and returned.

fetch_json(Method, Url, Payload, Options, Context)

-spec fetch_json(Method, Url, Payload, Options, Context) -> Result
                    when
                        Method :: get | post | delete | put | patch,
                        Url :: string() | binary(),
                        Payload :: list() | binary() | map(),
                        Options :: z_url_fetch:options(),
                        Context :: z:context(),
                        Result :: {ok, term()} | {error, term()}.

Perform a request and fetch JSON data from an URL. Let modules change the fetch options. On success, the returned body is parsed with jsxrecord and returned.

fetch_partial(Url, Options, Context)

-spec fetch_partial(Url, Options, Context) -> z_url_fetch:fetch_result()
                       when
                           Url :: string() | binary(),
                           Options :: z_url_fetch:options(),
                           Context :: z:context().

Fetch data from an URL. Let modules change the fetch options.

metadata(Url, Options, Context)

-spec metadata(string() | binary(), z_url_fetch:options(), z:context()) ->
                  {ok, z_url_metadata:metadata()} | {error, term()}.

Fetch the metadata from an URL. Let modules change the fetch options.