-module(dove@request). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([build_request/5, build_get/3, build_post/4, build_put/4, build_delete/3, build_patch/4]). -export_type([body/0]). -type body() :: {json, binary()} | {plain_text, binary()} | {octet_stream, bitstring()}. -spec build_request( gleam@http:method(), list({binary(), binary()}), binary(), list({binary(), binary()}), gleam@option:option(body()) ) -> gleam@http@request:request(gleam@option:option(body())). build_request(Method, Headers, Path, Query, Body) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_scheme(_pipe, http), _pipe@2 = gleam@http@request:set_method(_pipe@1, Method), _pipe@3 = gleam@http@request:set_path(_pipe@2, Path), _pipe@4 = gleam@http@request:set_query(_pipe@3, Query), _pipe@5 = gleam@http@request:set_body(_pipe@4, Body), gleam@list:fold( Headers, _pipe@5, fun(Request, Header) -> gleam@http@request:set_header( Request, erlang:element(1, Header), erlang:element(2, Header) ) end ). -spec build_get( list({binary(), binary()}), binary(), list({binary(), binary()}) ) -> gleam@http@request:request(gleam@option:option(body())). build_get(Headers, Path, Query) -> build_request(get, Headers, Path, Query, none). -spec build_post( list({binary(), binary()}), binary(), list({binary(), binary()}), body() ) -> gleam@http@request:request(gleam@option:option(body())). build_post(Headers, Path, Query, Body) -> build_request(post, Headers, Path, Query, {some, Body}). -spec build_put( list({binary(), binary()}), binary(), list({binary(), binary()}), body() ) -> gleam@http@request:request(gleam@option:option(body())). build_put(Headers, Path, Query, Body) -> build_request(put, Headers, Path, Query, {some, Body}). -spec build_delete( list({binary(), binary()}), binary(), list({binary(), binary()}) ) -> gleam@http@request:request(gleam@option:option(body())). build_delete(Headers, Path, Query) -> build_request(delete, Headers, Path, Query, none). -spec build_patch( list({binary(), binary()}), binary(), list({binary(), binary()}), body() ) -> gleam@http@request:request(gleam@option:option(body())). build_patch(Headers, Path, Query, Body) -> build_request(patch, Headers, Path, Query, {some, Body}).