Current section
Files
Jump to
Current section
Files
src/gleam@fetch.erl
-module(gleam@fetch).
-compile(no_auto_import).
-export([raw_send/1, send/1, to_fetch_request/1, from_fetch_response/1, read_text_body/1, read_json_body/1]).
-export_type([fetch_error/0, fetch_body/0, fetch_request/0, fetch_response/0]).
-type fetch_error() :: {network_error, binary()} |
unable_to_read_body |
invalid_json_body.
-type fetch_body() :: any().
-type fetch_request() :: any().
-type fetch_response() :: any().
-spec raw_send(fetch_request()) -> gleam@javascript@promise:promise({ok,
fetch_response()} |
{error, fetch_error()}).
raw_send(Field@0) ->
'../ffi.mjs':raw_send(Field@0).
-spec send(gleam@http@request:request(binary())) -> gleam@javascript@promise:promise({ok,
gleam@http@response:response(fetch_body())} |
{error, fetch_error()}).
send(Request) ->
_pipe = Request,
_pipe@1 = '../ffi.mjs':to_fetch_request(_pipe),
_pipe@2 = '../ffi.mjs':raw_send(_pipe@1),
gleam@javascript@promise:try_await(
_pipe@2,
fun(Resp) ->
'../../ffi.mjs':resolve(
{ok, '../ffi.mjs':from_fetch_response(Resp)}
)
end
).
-spec to_fetch_request(gleam@http@request:request(binary())) -> fetch_request().
to_fetch_request(Field@0) ->
'../ffi.mjs':to_fetch_request(Field@0).
-spec from_fetch_response(fetch_response()) -> gleam@http@response:response(fetch_body()).
from_fetch_response(Field@0) ->
'../ffi.mjs':from_fetch_response(Field@0).
-spec read_text_body(gleam@http@response:response(fetch_body())) -> gleam@javascript@promise:promise({ok,
gleam@http@response:response(binary())} |
{error, fetch_error()}).
read_text_body(Field@0) ->
'../ffi.mjs':read_text_body(Field@0).
-spec read_json_body(gleam@http@response:response(fetch_body())) -> gleam@javascript@promise:promise({ok,
gleam@http@response:response(gleam@dynamic:dynamic())} |
{error, fetch_error()}).
read_json_body(Field@0) ->
'../ffi.mjs':read_json_body(Field@0).