Back
Routes and URLs
Defining routes
In apps/<name>/routes.go:
var URLPatterns = []router.URLPattern{
router.Path("GET", "/", views.HomeView, "home"),
router.Path("POST", "/contato/", views.ContatoView, "contato"),
router.Path("GET", "/posts/<slug:str>/", views.PostView, "post_detalhe"),
router.Path("GET", "/users/<id:int>/", views.UserView, "user_detalhe"),
router.Path("DELETE", "/users/<id:int>/", views.DeleteUser, "user_delete"),
}
Path parameters — supported types
| Syntax | URL example | Description |
|---|---|---|
<name:str> |
/posts/my-post/ |
Any text without a slash |
<name:string> |
/posts/my-post/ |
Identical to str |
<id:int> |
/users/42/ |
Integer number |
<price:float> |
/produto/9.99/ |
Decimal number |
<slug:slug> |
/artigos/go-lang/ |
Text without a slash |
<uid:uuid> |
/item/550e8400.../ |
UUID |
<rest:path> |
/arquivos/a/b/c |
Multiple segments (with slashes) |
Trailing slash behavior
Kyrux accepts the route with and without a trailing slash automatically:
/contato → serves the view
/contato/ → serves the view (no redirect)
There's no need to register both variants.
Query string
Query parameters (?key=value) work on any route:
/busca?q=golang&page=2
/busca/?q=golang&page=2 ← both work
Accessed in the view via ctx.Query() (see section 6).
URL resolution in templates
<a href="{{ url "home" }}">Home</a>
<a href="{{ url "post_detalhe" }}">Post</a>
<form action="{{ url "contato" }}">...</form>
Registering advanced routes (without the CLI)
func Register(r *router.Router) {
router.Include(r, URLPatterns)
// Direct route without a URLPattern:
r.Handle("GET /ping", func(ctx *router.Context) {
ctx.JSON(200, map[string]string{"status": "ok"})
})
}