Skip to content

Std\Http

HTTP client and server — built on Std\Net and Std\String.

Provides Request/Response types, high-level client (get, post), and a simple server (serve). All networking via io_uring.

type Method = GET | POST | PUT | DELETE | PATCH | HEAD | OPTIONS

HTTP method.

type Request = Request {
method : Method,
path : String,
headers : Int,
body : String
}

HTTP request with method, path, headers, and body.

type Response = Response {
status : Int,
rawHeaders : String,
body : String
}

HTTP response with status code, raw headers string, and body.

HTTP GET shorthand.

get "example.com" 80 "/api"

post : String -> Int -> String -> String -> Response

Section titled “post : String -> Int -> String -> String -> Response”

HTTP POST shorthand.

post "example.com" 80 "/submit" "key=value"

request : Method -> String -> Int -> String -> Request

Section titled “request : Method -> String -> Int -> String -> Request”

Create a request with defaults.

send : String -> Int -> Request -> Response

Section titled “send : String -> Int -> Request -> Response”

Send an HTTP request to host:port and return the Response.

send "example.com" 80 (request GET "/" 0 "")

Parse an HTTP response string into a Response.

formatRequest : String -> Request -> String

Section titled “formatRequest : String -> Request -> String”

Format a Request into an HTTP/1.1 request string.

serve : String -> Int -> (Request -> Response) -> Int

Section titled “serve : String -> Int -> (Request -> Response) -> Int”

Start an HTTP server. Calls handler request for each incoming connection. The handler receives a Request and returns a Response. Runs forever (blocking).

serve "0.0.0.0" 8080 (\req -> ok "Hello!")

Create a Response with custom status and body.

Create a simple 200 OK response.

ok "Hello, World!"

Create a 404 Not Found response.

Create a 500 Internal Server Error response.