Skip to content

Routing

Routes are created using HTTP method constructors that return a Route value. Builder methods can be chained to attach metadata, middleware, and OpenAPI documentation.

func GET(path string, handler func(*Ctx) error) Route
func POST(path string, handler func(*Ctx) error) Route
func PUT(path string, handler func(*Ctx) error) Route
func PATCH(path string, handler func(*Ctx) error) Route
func DELETE(path string, handler func(*Ctx) error) Route
core.GET("/users", func(c *core.Ctx) error {
return c.OK("hello")
})

All builder methods return a new Route — they are safe to chain.

Groups the route under an OpenAPI tag.

core.GET("/users", handler).Tag("users")

.Describe(summary string, description ...string) Route

Section titled “.Describe(summary string, description ...string) Route”

Sets the OpenAPI summary and optional longer description.

core.GET("/users", handler).
Describe("List users", "Returns a paginated list of all users in the system")

Documents the request body type. Use the WithBody[T]() generic helper.

core.POST("/users", handler).
WithBody(core.WithBody[CreateUserDTO]())

Documents the response type and status code. Use the WithResponse[T](statusCode) generic helper.

core.POST("/users", handler).
WithResponse(core.WithResponse[User](201))

.WithQueryParam(name, typ string, required bool, desc ...string) Route

Section titled “.WithQueryParam(name, typ string, required bool, desc ...string) Route”

Adds a documented query parameter to the OpenAPI spec.

core.GET("/users", handler).
WithQueryParam("search", "string", false, "Filter by name").
WithQueryParam("limit", "integer", false, "Max results per page")

Type values: "string", "integer", "boolean", "number", "array"

Attaches one or more Fiber middlewares to the route.

core.GET("/admin", handler).
Use(authMiddleware, adminOnly)

Marks the route as requiring authentication in the OpenAPI spec.

core.DELETE("/users/:id", handler).
WithSecured("bearerAuth")

Marks the route as deprecated in the OpenAPI spec.

core.GET("/v1/users", handler).
WithDeprecated()

Creates a BodyMeta from a Go type. Used for OpenAPI schema generation.

core.WithBody[CreateUserDTO]()

WithResponse[T any](statusCode int) *ResponseMeta

Section titled “WithResponse[T any](statusCode int) *ResponseMeta”

Creates a ResponseMeta from a Go type and status code.

core.WithResponse[User](201)
core.WithResponse[core.Page[User]](200)
core.WithResponse[[]string](200)

Use app.Group() to prefix routes and share middleware:

v1 := app.Group("/api/v1")
v1.RegisterController(&UserController{})
// → GET /api/v1/users

With middleware:

protected := app.Group("/api/v1", authMiddleware)
protected.RegisterController(&UserController{})

Route exposes getters for inspection (used internally by OpenAPI builder):

r.Method() // "GET", "POST", etc.
r.Path() // "/users/:id"
r.Handler() // fiber.Handler
r.Middlewares() // []fiber.Handler
r.Summary()
r.Description()
r.Tags()
r.Secured()
r.Body()
r.Response()
r.QueryParams()
r.Deprecated()

Convert a func(*Ctx) error to a raw fiber.Handler:

h := core.WrapHandler(func(c *core.Ctx) error {
return c.OK("ok")
})
// h is a fiber.Handler

This is useful when integrating with middleware libraries that expect fiber.Handler.