This episode dissects fiber.Ctx — the object every request carries: request access, response and execution flow control, helper properties, and request extensions like port, namespace, and sendStream.

fiber.Ctx is the object that unifies request and response in a single handler. Episode 10 dissects Fiber v3's context: how to access request data, control the execution flow, and use request extensions like port, namespace, and sendStream.
At a glance there are many methods on Ctx, but they all fall into a few categories: request, response, flow, helpers, and more. Understanding the category map makes Ctx far easier to master than memorizing method by method.
Ctx provides direct access to request information. Some of the most used:
app.Get("/hello/:name", func(c fiber.Ctx) error {
log.Println("method:", c.Method())
log.Println("path:", c.Path())
log.Println("full URL:", c.BaseURL()+c.OriginalURL())
log.Println("host:", c.Hostname())
log.Println("ip:", c.IP())
log.Println("protocol:", c.Protocol())
log.Println("param:", c.Params("name"))
log.Println("query:", c.Query("sort"))
return c.SendString("ok")
})c.Method() returns the HTTP method, c.BaseURL() the scheme and host (e.g. http://localhost:3000), c.OriginalURL() the full path with query, c.IP() the sender's address, and c.Protocol() the request scheme. This combination of helpers is often used for logging, tracing, and building absolute links.
Besides reading data, Ctx controls the request's journey through the pipeline:
app.Use(func(c fiber.Ctx) error {
if c.IP() == "127.0.0.1" {
return c.Next()
}
return fiber.NewError(fiber.StatusForbidden, "akses lokal saja")
})c.Next() passes the request to the next handler; returning an error directly from middleware stops the pipeline and triggers the ErrorHandler. Other useful flow methods: c.SendStatus(status) sends a status with its standard message, and c.Redirect(url) moves the client.
Fiber v3 uses sendStream for streaming responses, and the request URI stores port and namespace details you can read in a handler:
app.Get("/info", func(c fiber.Ctx) error {
port := c.Request().URI().Port()
ns := c.Request().URI().Namespace()
return c.JSON(fiber.Map{
"port": port,
"namespace": ns,
})
})c.Request().URI().Port() returns the request port number, and c.Request().URI().Namespace() the namespace value sent in the URL. This information is useful when the application runs behind a proxy or needs to know a specific entry point.
The sendStream extension lets the server send a response as a chunk-by-chunk data stream — useful for large streams without holding all the data in memory:
app.Get("/stream", func(c fiber.Ctx) error {
c.SendStream(func() ([]byte, error) {
return []byte("chunk"), nil
}, fiber.StreamParams{Chunked: true})
return nil
})c.SendStream(fn, params) calls fn repeatedly to produce chunks until it returns io.EOF. With Chunked: true, the response uses chunked transfer-encoding. This is ideal for streaming large files or continuously growing data feeds.
Three methods often used together to control the response:
c.Status(201).JSON(fiber.Map{"id": 1})
c.Set("Content-Type", "application/pdf")
c.Append("X-Extra", "value")c.Status() sets the status code (default 200), c.Set() sets a single header, and c.Append() adds a value to a header that may already exist. Once the response is sent, c.Status() can no longer change the status — so always call status before sending the body.
curl http://localhost:3000/hello/budi?sort=desc
curl http://localhost:3000/info
curl http://localhost:3000/streamThe first request prints all the request helper properties to the server terminal. /info returns the port and namespace, and /stream sends a chunked response the client receives as a single payload.
Key takeaways:
fiber.Ctx combines request, response, and flow in one object.Method, Path, BaseURL, OriginalURL, Hostname, IP, Protocol, Params, Query.c.Next() and errors from middleware control the pipeline flow.c.Request().URI().Port() and .Namespace() read entry point details.c.SendStream streams chunked responses with StreamParams{Chunked}.Status, Set, and Append control response headers and status.In the next episode, episode 11, we discuss Fiber v3 breaking changes — the significant differences from v2, the variadic handler shift, middleware adjustments, and how to migrate existing applications.