Kadabra v0.3.5 Kadabra

HTTP/2 client for Elixir.

Summary

Functions

Closes an existing connection

Makes a GET request

Opens a new connection

Pings an existing connection

Makes a POST request

Makes a PUT request

Makes a request with given headers

Makes a request with given headers and body

Functions

close(pid)
close(pid) :: :ok

Closes an existing connection.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> Kadabra.close(pid)
iex> receive do
...>   {:closed, _pid} -> "connection closed!"
...> end
"connection closed!"
get(pid, path)

Makes a GET request.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> Kadabra.get(pid, "/reqinfo")
:ok
iex> response = receive do
...>   {:end_stream, response} -> response
...> end
iex> {response.id, response.status}
{1, 200}
open(uri, scheme, opts \\ [])
open(charlist, :https, Keyword.t) ::
  {:ok, pid} |
  {:error, term}

Opens a new connection.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> is_pid(pid)
true
ping(pid)

Pings an existing connection.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> Kadabra.ping(pid)
iex> receive do
...>   {:pong, _pid} -> "got pong!"
...> end
"got pong!"
post(pid, path, payload)

Makes a POST request.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> Kadabra.post(pid, "/", "test=123")
:ok
iex> response = receive do
...>   {:end_stream, response} -> response
...> end
iex> {response.id, response.status}
{1, 200}
put(pid, path, payload)

Makes a PUT request.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> Kadabra.put(pid, "/crc32", "test")
:ok
iex> stream = receive do
...>   {:end_stream, stream} -> stream
...> end
iex> stream.status
200
iex> stream.body
"bytes=4, CRC32=d87f7e0c"
request(pid, headers)

Makes a request with given headers.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> path = "/reqinfo" # Route echoes PUT body in uppercase
iex> headers = [
...>   {":method", "GET"},
...>   {":path", path},
...> ]
iex> Kadabra.request(pid, headers)
iex> response = receive do
...>   {:end_stream, %Kadabra.Stream.Response{} = response} -> response
...> after 5_000 -> :timed_out
...> end
iex> {response.id, response.status}
{1, 200}
request(pid, headers, body)

Makes a request with given headers and body.

Examples

iex> {:ok, pid} = Kadabra.open('http2.golang.org', :https)
iex> path = "/ECHO" # Route echoes PUT body in uppercase
iex> body = "sample echo request"
iex> headers = [
...>   {":method", "PUT"},
...>   {":path", path},
...> ]
iex> Kadabra.request(pid, headers, body)
iex> response = receive do
...>   {:end_stream, %Kadabra.Stream.Response{} = response} -> response
...> after 5_000 -> :timed_out
...> end
iex> {response.id, response.status, response.body}
{1, 200, "SAMPLE ECHO REQUEST"}