Welcome to the Gluegun documentation!
Quick Start
Open a Gun connection, wait for it to be ready, send a GET request, and collect the full response in memory.
import gleam/intimport gleam/ioimport gluegun/clientimport gluegun/connectionimport gluegun/requestimport gluegun/response
pub fn main() { let timeout = connection.Milliseconds(5000)
let assert Ok(conn) = connection.options() |> connection.open(host: "example.com", port: 80) let assert Ok(_protocol) = connection.await_up(conn, timeout)
let assert Ok(res) = client.new(request.Get, "/") |> client.with_timeout(timeout: timeout) |> client.send(connection: conn)
io.println("status: " <> int.to_string(response.status(res)))
case response.body_text(res) { Ok(text) -> io.println(text) Error(_) -> io.println("response body was not UTF-8") }
let assert Ok(Nil) = connection.close(conn)}Key idea
Section titled “Key idea”Gluegun separates connection setup from requests:
- Open a connection to a host and port.
- Wait for Gun to report the negotiated protocol.
- Send requests using paths such as
/,/api/items, or/health. - Close or shut down the connection when you are finished.
connection.Milliseconds(Int) constructs a finite Timeout; use connection.Infinity when you want to wait without bound. The same Timeout value is reused for connection readiness, request bodies, and message receives.
Use connection.close for normal teardown. Use connection.shutdown only when a connection appears stuck — it terminates the Gun process immediately without graceful close.
For complete module, type, and function details, use the API reference.