/http/client
Async and sync HTTP/HTTPS client with connection pooling, headers, timeouts, and streaming bodies.
Functions & symbols#
Client#
Constructs a reusable pooled HTTP/HTTPS client bound to `*runtime*`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
options | Map | optional | Optional client config {:timeout-ms :user-agent :follow-redirects} |
Any(let client (http/Client {:timeout-ms 10000}))close-stream#
Closes an open SSE `Event-Stream` and cancels its underlying HTTP response stream.
| Parameter | Type | Optional | Description |
|---|---|---|---|
stream | Event-Stream | required | Open SSE stream handle |
Any(http/close-stream stream)content-type-of#
Returns the `Content-Type` header from an HTTP request or response Map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
msg | Map | required | HTTP request or response Map |
default | Any | optional | Optional default |
Any(http/content-type-of resp)delete#
Performs an HTTP `DELETE` request returning a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
headers | Map | optional | Optional request headers map |
Any(let resp (http/delete client "https://api.example.com/items"))get#
Performs an HTTP `GET` request returning a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
headers | Map | optional | Optional request headers map |
Any(let resp (http/get client "https://api.example.com/items"))get-text#
Performs a `GET` request and returns the response body decoded directly as UTF-8 text.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client |
url | String | required | Target URL |
headers | Map | optional | Optional headers |
Any(let body (http/get-text client "https://example.com"))head#
Performs an HTTP `HEAD` request returning a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
headers | Map | optional | Optional request headers map |
Any(let resp (http/head client "https://api.example.com/items"))header-of#
Looks up an HTTP header case-insensitively on a request or response Map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
msg | Map | required | HTTP request or response Map |
name | String | KeySymbol | required | Case-insensitive header name |
default | Any | optional | Optional default if absent |
Any(http/header-of resp :content-type)options#
Performs an HTTP `OPTIONS` request returning a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
headers | Map | optional | Optional request headers map |
Any(let resp (http/options client "https://api.example.com/items"))patch#
Performs an HTTP `PATCH` request with `body` and returns a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
body | String | Slab | Map | required | Request body payload |
headers | Map | optional | Optional request headers map |
Any(let resp (http/patch client "https://api.example.com/items" payload {:content-type "application/json"}))post#
Performs an HTTP `POST` request with `body` and returns a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
body | String | Slab | Map | required | Request body payload |
headers | Map | optional | Optional request headers map |
Any(let resp (http/post client "https://api.example.com/items" payload {:content-type "application/json"}))put#
Performs an HTTP `PUT` request with `body` and returns a response Map {:status :headers :body}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client created with Client |
url | String | required | Target HTTP or HTTPS URL |
body | String | Slab | Map | required | Request body payload |
headers | Map | optional | Optional request headers map |
Any(let resp (http/put client "https://api.example.com/items" payload {:content-type "application/json"}))receive-event#
Reads the next parsed Server-Sent Event `{:event :data :id :retry}`, or `()` when the stream closes.
| Parameter | Type | Optional | Description |
|---|---|---|---|
stream | Event-Stream | required | Open SSE stream handle |
Any(while (let ev (http/receive-event stream)) (say ev:data))request#
Executes an arbitrary HTTP request described by `req-map` and returns `{:status :headers :body}`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client |
req | Map | required | Request spec {:method :url [:headers :body]} |
Any(http/request client {:method "GET" :url "https://example.com"})request-sse#
Opens a Server-Sent Events (SSE) HTTP stream handle for incremental reading via `receive-event`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client | Client | required | HTTP client |
req | Map | required | Request spec {:method :url [:headers :body]} |
Any(let stream (http/request-sse client {:method "GET" :url "https://api.example.com/events"}))