Module

pooka/httpc

src/pooka/httpc.pooka

An HTTP client, using the one that comes with Erlang.

Pooka
import httpc

main() {
  match httpc.get("https://example.org/") {
    Ok(reply) -> echo reply.status
    Error(problem) -> echo httpc.describe(problem)
  }
}

Requests and responses are the ones from pooka/http, the same a server receives. TLS certificates are checked against the operating system's trusted authorities, and connections are kept open and reused.

API reference

class

Options

src/pooka/httpc.pooka:25
class Options

How a request is sent. Start with defaults, then adjust.

field

timeout

src/pooka/httpc.pooka:26
let timeout: Int
INFERREDInt
field

connect_timeout

src/pooka/httpc.pooka:27
let connect_timeout: Int
INFERREDInt
field

follow_redirects

src/pooka/httpc.pooka:28
let follow_redirects: Bool
INFERREDBool
field

verify_tls

src/pooka/httpc.pooka:29
let verify_tls: Bool
INFERREDBool
constructor

new

src/pooka/httpc.pooka:31
new(
    timeout: Int,
    connect_timeout: Int,
    follow_redirects: Bool,
    verify_tls: Bool
  )
INFERREDfn(Int, Int, Bool, Bool) -> pooka/httpc.Options
method

with_timeout

src/pooka/httpc.pooka:44
with_timeout(milliseconds: Int) -> Options
INFERREDfn(Int) -> pooka/httpc.Options

How long to wait for the whole response, in milliseconds.

method

with_connect_timeout

src/pooka/httpc.pooka:49
with_connect_timeout(milliseconds: Int) -> Options
INFERREDfn(Int) -> pooka/httpc.Options

How long to wait for the connection, in milliseconds.

method

following_redirects

src/pooka/httpc.pooka:54
following_redirects() -> Options
INFERREDfn() -> pooka/httpc.Options

Follow redirects to their end, instead of returning the redirect.

method

without_tls_verification

src/pooka/httpc.pooka:60
without_tls_verification() -> Options
INFERREDfn() -> pooka/httpc.Options

Accept any certificate. Only for servers you control, such as a local one with a self-signed certificate.

function

defaults

src/pooka/httpc.pooka:67
defaults() -> Options
INFERREDfn() -> pooka/httpc.Options

Thirty seconds for a response, ten to connect, no redirects followed, and certificates checked.

class

HttpcError

src/pooka/httpc.pooka:72
class HttpcError

Why a request got no response.

class

BadUrl

src/pooka/httpc.pooka:75
class BadUrl(reason: String) is HttpcError

The URL could not be read.

field

reason

src/pooka/httpc.pooka:75
reason: String
INFERREDString
constructor

new

src/pooka/httpc.pooka:75
INFERREDfn(String) -> pooka/httpc.BadUrl
class

CouldNotConnect

src/pooka/httpc.pooka:79
class CouldNotConnect(reason: String) is HttpcError

No connection: the host is unknown, refused, or the certificate is not trusted.

field

reason

src/pooka/httpc.pooka:79
reason: String
INFERREDString
constructor

new

src/pooka/httpc.pooka:79
INFERREDfn(String) -> pooka/httpc.CouldNotConnect
class

TimedOut

src/pooka/httpc.pooka:82
class TimedOut is HttpcError

The connection or the response took too long.

class

Unsupported

src/pooka/httpc.pooka:85
class Unsupported(reason: String) is HttpcError

A method this client cannot send.

field

reason

src/pooka/httpc.pooka:85
reason: String
INFERREDString
constructor

new

src/pooka/httpc.pooka:85
INFERREDfn(String) -> pooka/httpc.Unsupported
class

Failed

src/pooka/httpc.pooka:88
class Failed(reason: String) is HttpcError

Anything else that went wrong on the way.

field

reason

src/pooka/httpc.pooka:88
reason: String
INFERREDString
constructor

new

src/pooka/httpc.pooka:88
INFERREDfn(String) -> pooka/httpc.Failed
function

describe

src/pooka/httpc.pooka:91
describe(problem: HttpcError) -> String
INFERREDfn(pooka/httpc.HttpcError) -> String

A sentence about what went wrong.

function

send

src/pooka/httpc.pooka:110
send(request: Request) -> Result(Response, HttpcError)
INFERREDfn($package/pooka_http/pooka/http.Request) -> Result($package/pooka_http/pooka/http.Response, pooka/httpc.HttpcError)

Send a request, and wait for the response. Any status counts as a response, 404 and 500 included; check reply.status.

function

send_with

src/pooka/httpc.pooka:115
send_with(request: Request, options: Options) -> Result(Response, HttpcError)
INFERREDfn($package/pooka_http/pooka/http.Request, pooka/httpc.Options) -> Result($package/pooka_http/pooka/http.Response, pooka/httpc.HttpcError)

Send a request with your own options.

function

get

src/pooka/httpc.pooka:148
get(url: String) -> Result(Response, HttpcError)
INFERREDfn(String) -> Result($package/pooka_http/pooka/http.Response, pooka/httpc.HttpcError)

GET a URL.

function

post_text

src/pooka/httpc.pooka:156
post_text(url: String, body: String) -> Result(Response, HttpcError)
INFERREDfn(String, String) -> Result($package/pooka_http/pooka/http.Response, pooka/httpc.HttpcError)

POST text to a URL.

function

post_json

src/pooka/httpc.pooka:164
post_json(url: String, body: String) -> Result(Response, HttpcError)
INFERREDfn(String, String) -> Result($package/pooka_http/pooka/http.Response, pooka/httpc.HttpcError)

POST JSON text, already encoded, to a URL.