nhttpc

Hex.pm CI

HTTP/1.1, HTTP/2, HTTP/3 and WebSocket client for Erlang/OTP 27+.

Getting started

%% rebar.config
{deps, [nhttpc]}.

One-shot requests

{ok, #{status := 200, body := Body}} =
    nhttpc:get(<<"https://api.example.com/users/42">>).

{ok, Resp} = nhttpc:post(
    <<"https://api.example.com/users">>,
    <<"{\"name\":\"alice\"}">>,
    #{headers => [{<<"content-type">>, <<"application/json">>}]}).

Connection pools

{ok, _} = nhttpc:start_link(api_pool, #{
    host => <<"api.example.com">>,
    port => 443,
    versions => [http2, http1_1]
}).

{ok, Resp} = nhttpc:get(<<"https://api.example.com/users">>,
                        #{via => {pool, api_pool}}).

Async requests

Every async surface delivers {nhttpc, Handle, Event} to its owner. cancel/1 returns only after draining those events from the mailbox.

{ok, Req} = nhttpc:url(get, <<"https://api.example.com/users/42">>),
{ok, H} = nhttpc:send(Req),
{ok, Resp} = nhttpc:await(H, 5_000).

Features

Documentation

nhttpc on HexDocs

License

Apache License 2.0