Path: redb-route/redb.Route.Controllers/Attributes/HttpMethodAttributes.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Controllers/Attributes/HttpMethodAttributes.cs
----
namespace redb.Route.Controllers.Attributes;
/// HTTP method type for route matching.
public enum HttpMethodType
{
/// GET request.
Get,
/// POST request.
Post,
/// PUT request.
Put,
/// DELETE request.
Delete,
/// PATCH request.
Patch
}
///
/// Base attribute for HTTP method markers on controller actions.
/// These are route-table markers, not transport directives.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public abstract class HttpMethodAttribute : Attribute
{
/// HTTP method this action responds to.
public HttpMethodType Method { get; }
/// Optional sub-template (e.g. "{id}").
public string? Template { get; }
/// HTTP method type.
/// Optional sub-template appended to the controller route.
protected HttpMethodAttribute(HttpMethodType method, string? template = null)
{
Method = method;
Template = template;
}
}
/// Marks a controller action as handling GET requests.
public sealed class HttpGetAttribute : HttpMethodAttribute
{
/// Optional sub-template (e.g. "{id}").
public HttpGetAttribute(string? template = null) : base(HttpMethodType.Get, template) { }
}
/// Marks a controller action as handling POST requests.
public sealed class HttpPostAttribute : HttpMethodAttribute
{
/// Optional sub-template (e.g. "search").
public HttpPostAttribute(string? template = null) : base(HttpMethodType.Post, template) { }
}
/// Marks a controller action as handling PUT requests.
public sealed class HttpPutAttribute : HttpMethodAttribute
{
/// Optional sub-template (e.g. "{id}").
public HttpPutAttribute(string? template = null) : base(HttpMethodType.Put, template) { }
}
/// Marks a controller action as handling DELETE requests.
public sealed class HttpDeleteAttribute : HttpMethodAttribute
{
/// Optional sub-template (e.g. "{id}").
public HttpDeleteAttribute(string? template = null) : base(HttpMethodType.Delete, template) { }
}
/// Marks a controller action as handling PATCH requests.
public sealed class HttpPatchAttribute : HttpMethodAttribute
{
/// Optional sub-template (e.g. "{id}").
public HttpPatchAttribute(string? template = null) : base(HttpMethodType.Patch, template) { }
}