A minimal, low-level HTTP client for Erlang.
HTTP/1.1 and HTTP/2 support. Pure Erlang. Zero dependencies.
Fast. Small API. Proper HTTP/1.1 and HTTP/2 support. Works with both protocols transparently.
Add to your rebar.config:
{deps, [gen_http]}.Add to your mix.exs:
{:gen_http, "~> 0.1"}Send a request:
{ok, Conn} = gen_http:connect(http, "httpbin.org", 80),
{ok, Conn2, Ref} = gen_http:request(Conn, <<"GET">>, <<"/get">>, [], <<>>),
receive
Msg ->
case gen_http:stream(Conn2, Msg) of
{ok, Conn3, [{status, Ref, 200}, {headers, Ref, Headers}, {data, Ref, Body}, {done, Ref}]} ->
io:format("Body: ~s~n", [Body])
end
end.HTTPS with automatic HTTP/2 negotiation:
{ok, Conn} = gen_http:connect(https, "www.google.com", 443),
{ok, Conn2, Ref} = gen_http:request(Conn, <<"GET">>, <<"/">>, [], <<>>).
%% Same API, different protocolSee the Getting Started guide for POST requests, passive mode, response collection loops, and more.
156 tests covering RFC 7540 (HTTP/2) and RFC 7541 (HPACK). All frame types, stream states, flow control, priority handling, HPACK compression, and error conditions.
Tested against h2-client-test-harness. 100% pass rate.
- Getting Started -- installation, first request, collecting responses
- Architecture -- process-less design, module layout, protocol negotiation
- Active and Passive Modes -- choosing the right I/O model
- Error Handling -- structured errors, retries, pattern matching
- SSL Certificates -- TLS config, custom CAs, ALPN
SSL/H2/ALPN tests need nghttpx (from nghttp2). Install on macOS with brew install nghttp2. Suites that need it skip gracefully if it's not installed.
# Run all tests
rebar3 test
# Run specific test types
rebar3 eunit # Unit tests
rebar3 ct # Integration tests
rebar3 proper # Property-based tests
# HTTP/2 compliance tests (excluded by default, requires separate Docker harness)
rebar3 ct --suite=h2_compliance_SUITEEarly development. API may change.
Apache 2.0