Routing

Learn how to define routes and handle HTTP methods.


Basic Routing

Routes are defined on the main router instance. The basic method accepts a URI and a closure.

r.GET("/", func(c *routix.Context) error {
    return c.String(200, "Hello World")
})

Supported Methods

Routix supports all standard HTTP verbs:

r.GET("/users", handler)
r.POST("/users", handler)
r.PUT("/users/:id", handler)
r.PATCH("/users/:id", handler)
r.DELETE("/users/:id", handler)
r.OPTIONS("/users", handler)

Route Parameters

You can capture segments of the URI within your route by defining route parameters:

r.GET("/posts/:id", func(c *routix.Context) error {
    id := c.Params["id"]
    return c.String(200, "Post ID: %s", id)
})