Core Concepts
Routing
Ginject parses controller method names into HTTP routes automatically. Learn the full token reference, versioning, and wildcard patterns.
Routing
Ginject derives HTTP routes from controller method names at startup. No annotations, struct tags, or code generation are needed. The method name is tokenized on underscores and each token has a semantic meaning.
Token Reference
| Token | HTTP Method / Meaning | Example method → route |
|---|---|---|
READ | GET | READ → GET / |
CREATE | POST | CREATE → POST / |
UPDATE | PUT | UPDATE → PUT / |
MODIFY | PATCH | MODIFY → PATCH / |
DELETE | DELETE | DELETE → DELETE / |
PREFLIGHT | OPTIONS | PREFLIGHT → OPTIONS / |
BY | Path parameter (:token) | READ_BY_ID → GET /:id |
AND | Additional path segment | READ_BY_ID_AND_NAME → GET /:id/:name |
OF | Named sub-resource | READ_OF_USER → GET /user |
ANY | Wildcard (*) | READ_ANY → GET /* |
VERSION | API version prefix | READ_VERSION_1 → versioned route |
FILE | Static file serving | READ_FILE → static file handler |
Basic Routes
Multiple Path Parameters
Chain BY and AND for multiple params in the same route:
Sub-Resources with OF
Wildcard Routes
Wildcards match all remaining path segments.
Static File Serving
Route Versioning
Enable versioning on the app before creating:
Then append _VERSION_N to method names:
Versioning modes:
| Mode | URL pattern |
|---|---|
versioning.URL | /v1/users, /v2/users |
versioning.Header | Accept-Version: 1 header |
versioning.Query | /users?version=1 |
Global Prefix
Set a global prefix that applies to all routes in the app:
Path Parameters
Access path parameters via ctx.Param in handler arguments:
Query Parameters
Access query parameters via ctx.Query:
Naming Conventions
- Tokens are case-insensitive in the parsing, but must be uppercase in the method name for Go to export them.
- All tokens between
BY,AND, andOFare lowercased for the actual path segment.READ_BY_USER_IDproduces/:userID(camelCased from the multi-word segment).