Skip to content

Routing ​

A route connects an HTTP method and path to a handler. For example, GET /api/v1/users/42 calls a controller that looks up user 42.

Where Routes Live ​

Controllers such as internal/users/controller.go expose routes. The owning app groups them in app/routes.go, or app/admin/routes.go for an additional app named admin. Use the same route paths when running HTTP on its own or alongside other runtimes.

Add a Route ​

Use forj make:controller users to create a controller and register its routes. Your First Route shows the exact files, service wiring, and HTTP check.

Controller Routes ​

Controllers return a []web.Route with each method, path, and handler.

go
func (c *Controller) Routes() []web.Route {
	return []web.Route{
		web.NewRoute(http.MethodGet, "/users/:id", c.Show),
		web.NewRoute(http.MethodPost, "/users", c.Store),
	}
}

Handlers use web.Context. Keep application behavior in a service and call it from the handler.

Route Groups ​

In an Auth-enabled App, ProvideRoutes can mount public and protected routes under the same prefix. Pass authService.RequireAuth to the group whose routes require a session.

go
return []web.RouteGroup{
	web.NewRouteGroup("/api/v1", publicRoutes),
	web.NewRouteGroup("/api/v1", protectedRoutes, authService.RequireAuth),
}

Put shared prefixes and middleware on the group.

Route Naming ​

Use REST-ish paths that describe resources. Let HTTP methods carry the action:

text
GET  /api/v1/users/:id
POST /api/v1/reports

Avoid RPC-style paths such as /api/v1/get-user for normal resource operations. See Naming Conventions for the full naming map.

Listing Routes ​

Run this from the Project root to see which routes the app registered.

bash
forj route:list

Use forj admin route:list to inspect the admin app. The table includes route registration details that startup logs may omit.

Framework Routes ​

The HTTP runtime also registers framework-owned routes such as:

  • /-/health
  • /-/ready
  • /swagger
  • /swagger/doc.json
  • /metrics when metrics are enabled
  • Lighthouse routes when Lighthouse is enabled

Keep application route registration in the owning App's route file and reserve framework paths for their operational handlers. See HTTP Runtime for how the runtime serves and observes them.

Next Steps ​