Skip to content

codeadict/gen_http

Repository files navigation

gen_http

CI codecov HTTP/2 Compliance Module Version Hex Docs Hex Downloads RFC 7540 RFC 7541

A minimal, low-level HTTP client for Erlang.

HTTP/1.1 and HTTP/2 support. Pure Erlang. Zero dependencies.

Why?

Fast. Small API. Proper HTTP/1.1 and HTTP/2 support. Works with both protocols transparently.

Quick Start

Erlang

Add to your rebar.config:

{deps, [gen_http]}.

Elixir

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 protocol

See the Getting Started guide for POST requests, passive mode, response collection loops, and more.

HTTP/2 Compliance

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.

Documentation

Testing

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_SUITE

Project Status

Early development. API may change.

License

Apache 2.0

About

HTTP client for Erlang with support for HTTP/1 and HTTP/2 (Inspired by Mint)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages