Quick Start
Open a Gun connection. Wait until it is ready. Send a GET request. Collect the full response in memory.
import gleam/intimport gleam/ioimport gleam/resultimport gluegun/clientimport gluegun/connectionimport gluegun/requestimport gluegun/response
pub fn main() { let timeout = connection.Milliseconds(5000)
use conn <- result.try( connection.options() |> connection.open(host: "example.com", port: 80), ) use _protocol <- result.try(connection.await_up(conn, timeout))
use res <- result.try( 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") }
connection.close(conn)}Key idea
Section titled “Key idea”Gluegun keeps connection setup and requests separate:
- Open a connection to a host and port.
- Wait until Gun reports the negotiated protocol.
- Send requests with paths such as
/,/api/items, or/health. - Close or shut down the connection when you are finished.
If you have a full URL, parse it with gleam/uri before you call Gluegun. Gluegun accepts only the separate host, port, transport, path, and query values.
connection.Milliseconds(Int) makes a finite Timeout. Use connection.Infinity to wait without a limit. The same Timeout value applies to connection readiness, request bodies, and message receives.
Use connection.close for usual teardown. Use connection.shutdown only when a connection seems stuck. shutdown stops the Gun process immediately, without a graceful close.
For full module, type, and function details, see the API reference.

