Quick Start
Open a Gun connection. Wait until it is ready. Send a GET request. Collect the full response in memory.
Before you start, install Gluegun and confirm that the package target is erlang.
import gleam/intimport gleam/ioimport gleam/resultimport gluegun/clientimport gluegun/connectionimport gluegun/requestimport gluegun/response
pub fn main() { use timeout <- result.try(connection.milliseconds(5000))
use conn <- result.try( connection.open( connection.options(), 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)}Run the example:
gleam runYou should see status: 200, followed by the HTML response from example.com.
If the connection does not open or the request times out, use the troubleshooting guide.
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) validates and returns 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 to stop a connection through Gun's supervisor. connection.shutdown requests graceful shutdown without waiting for exit. Use connection.terminate for a stuck connection or deadline cleanup; it forces exit and flushes the caller's Gun messages. See Message Flow.
For full module, type, and function details, use the API reference.

