http-client

An HTTP client for Carp that supports both HTTP and HTTPS.

Built on the sockets, http, and tls libraries. Uses a Connection union type to dispatch transparently over plain TCP or TLS-encrypted streams.

GET request

(load "http-client.carp")

(defn main []
  (match (Client.get "https://example.com/")
    (Result.Success r) (println* (Response.body &r))
    (Result.Error e) (IO.errorln &e)))

POST with JSON

(match (Client.post "https://httpbin.org/post"
         {@"Content-Type" [@"application/json"]}
         "{\"key\": \"value\"}")
  (Result.Success r) (println* (Response.body &r))
  (Result.Error e) (IO.errorln &e))

Requirements

Requires OpenSSL for HTTPS support (via the tls library). Plain HTTP works without OpenSSL.