Kadabra v0.3.8 Kadabra View Source

HTTP/2 client for Elixir.

Link to this section 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

Link to this section Functions

Link to this function close(pid) View Source
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!"

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}
Link to this function open(uri, scheme, opts \\ []) View Source
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

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!"
Link to this function post(pid, path, payload) View Source

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}

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"

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}
Link to this function request(pid, headers, body) View Source

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"}