Custom HTTP routes
Method-level HTTP routes with [HttpGet] through [HttpOptions] in C#
Convention vs custom
| Mode | How | Mount path |
|---|---|---|
| Convention | Methods named Get, Post, Put, Patch, Delete, Head, Options (case-insensitive) | Class base path from [Route] |
| Custom | [HttpGet] … [HttpOptions] on any method | Base path joined with the template |
Both can live on the same class.
Method attributes
Defined in FusionFramework (HttpMethodAttributes.cs). Each takes a route template in the constructor:
| Attribute | HTTP method |
|---|---|
[HttpGet] | GET |
[HttpPost] | POST |
[HttpPut] | PUT |
[HttpPatch] | PATCH |
[HttpDelete] | DELETE |
[HttpHead] | HEAD |
[HttpOptions] | OPTIONS |
Named properties on every attribute: Tags, Desc, Title, Deprecated.
Shared options
| Property | Behavior |
|---|---|
Tags | null inherits from [Route]; non-null (including empty) overrides |
Desc | Operation description |
Title | Operation summary / title |
Deprecated | Mark the operation deprecated |
Path joining and tokens
- Relative templates (no leading
/) join to the class[Route]base path. - Absolute templates starting with
/ignore the class base and mount at that path. [module]expands from the class name (UserModule→user).[action]expands from the handler name, stripping a trailingAction/ACTIONthen lowercasing (UserAction→user).
Example (GET + POST)
using FusionFramework;
[Route("/api/[module]", Tags = new[] { "users" })]
public class UserModule : FusionBaseApi
{
// Convention: GET /api/user
public object Get() =>
Response(new { mode = "convention" }, Status.HTTP_SUCCESS);
// Custom: GET /api/user/test/user
[HttpGet("test/[action]", Title = "User action")]
public object UserAction() =>
Response(new { mode = "custom", action = "user" }, Status.HTTP_SUCCESS);
// Custom: POST /api/user/create/create
[HttpPost("create/[action]", Title = "Create user", Tags = new[] { "users", "write" })]
public object CreateAction() =>
Response(new { created = true }, Status.HTTP_SUCCESS);
// Absolute: DELETE /admin/users/purge
[HttpDelete("/admin/users/purge", Deprecated = true)]
public object Purge() =>
Response(new { purged = true }, Status.HTTP_SUCCESS);
}Registration
Call Route.Register<UserModule>() (or register via your host bootstrap) before Listen().
Sample: examples/custom_http_routes.cs.