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.
For complete module, type, and function details, use the API reference.