/kadabra

HTTP/2 client for Elixir

Primary LanguageElixirMIT LicenseMIT

Build Status Coverage Status Hex.pm Hex.pm

Kadabra

HTTP/2 client for Elixir

Written to manage HTTP/2 connections for pigeon. Very much a work in progress.

Installation

Requires Elixir 1.6/OTP 19.2 or later.

Add kadabra to your mix.exs:

def deps do
  [
    {:kadabra, "~> 0.6.1"}
  ]
end

Usage

{:ok, pid} = Kadabra.open("https://http2.codedge.dev")
Kadabra.get(pid, "/")
receive do
  {:end_stream, %Kadabra.Stream.Response{} = stream} ->
  IO.inspect stream
after 5_000 ->
  IO.puts "Connection timed out."
end

%Kadabra.Stream.Response{
  body: "<html>\\n<body>\\n<h1>Go + HTTP/2</h1>\\n\\n<p>Welcome to..."
  headers: [
    {":status", "200"},
    {"content-type", "text/html; charset=utf-8"},
    {"content-length", "1708"},
    {"date", "Sun, 16 Oct 2016 21:20:47 GMT"}
  ],
  id: 1,
  status: 200
}

Making Requests Manually

{:ok, pid} = Kadabra.open("https://http2.codedge.dev")

path = "/ECHO" # Route echoes PUT body in uppercase
body = "sample echo request"
headers = [
  {":method", "PUT"},
  {":path", path},
]

Kadabra.request(pid, headers, body)

receive do
  {:end_stream, %Kadabra.Stream.Response{} = stream} ->
  IO.inspect stream
after 5_000 ->
  IO.puts "Connection timed out."
end

%Kadabra.Stream.Response{
  body: "SAMPLE ECHO REQUEST",
  headers: [
    {":status", "200"},
    {"content-type", "text/plain; charset=utf-8"},
    {"date", "Sun, 16 Oct 2016 21:28:15 GMT"}
  ],
  id: 1,
  status: 200
}

Contributing

Testing

Unit tests can be run with mix test or mix coveralls.html.

Formatting

This project uses Elixir's mix format and Prettier for formatting. Add hooks in your editor of choice to run it after a save. Be sure it respects this project's .formatter.exs.

Commits

Git commit subjects use the Karma style.

License

Copyright (c) 2016-2024 Codedge LLC (https://www.codedge.io/)

This library is MIT licensed. See the LICENSE for details.