ESC
Type to search...
S
Soli Docs

HTTP Functions

HTTP client for GET, POST, PUT, PATCH, DELETE requests with JSON support and parallel requests.

Basic HTTP Requests

http_get(url, options?)

Perform an HTTP GET request. Returns { "status": Int, "body": String, "headers": Hash }.

let resp = http_get("https://api.example.com/users")
if resp["status"] == 200 {
    println(resp["body"])
}
http_post(url, body, options?)

Perform an HTTP POST request with a body.

let resp = http_post(
    "https://api.example.com/users",
    "name=Alice",
    { "headers": { "Content-Type": "application/x-www-form-urlencoded" } }
)

JSON HTTP Methods

http_get_json(url)

GET request with automatic JSON parsing of response body.

let data = http_get_json("https://api.example.com/users/1")
println(data["body"]["name"])
http_post_json(url, data)

POST request with automatic JSON serialization.

let resp = http_post_json(
    "https://api.example.com/users",
    { "name": "Alice", "email": "[email protected]" }
)

Generic HTTP Request

http_request(method, url, options?)

Perform any HTTP method (GET, POST, PUT, PATCH, DELETE, etc.).

let resp = http_request("DELETE", "https://api.example.com/users/1")
let resp = http_request("PATCH", url, { "body": json, "headers": headers })

Status Code Helpers

http_ok(resp)

Check if status is exactly 200

http_success(resp)

Check if status is 2xx

http_redirect(resp)

Check if status is 3xx

http_client_error(resp)

Check if status is 4xx

http_server_error(resp)

Check if status is 5xx

Parallel Requests

http_get_all(urls)

Execute multiple GET requests in parallel.

let responses = http_get_all([
    "https://api.example.com/users",
    "https://api.example.com/posts"
])
http_parallel(requests)

Execute multiple requests of different methods in parallel.

let responses = http_parallel([
    { "method": "GET", "url": "https://api.example.com/users" },
    { "method": "POST", "url": "https://api.example.com/logs", "body": "{}" }
])