Skip to content

Routing

WARNING

The route argument to method name matching is case-sensitive.

Wolverine HTTP endpoints need to be decorated with one of the [WolverineVerb("route")] attributes that expresses the routing argument path in standard ASP.Net Core syntax (i.e., the same as when using MVC Core or Minimal API).

If a parameter argument to the HTTP handler method exactly matches a route argument, Wolverine will treat that as a route argument and pass the route argument value at runtime from ASP.Net Core to your handler method. To make that concrete, consider this simple case from the test suite:

cs
[WolverineGet("/name/{name}")]
public static string SimpleStringRouteArgument(string name)
{
    return $"Name is {name}";
}

snippet source | anchor

In the sample above, the name argument will be the value of the route argument at runtime. Here's another example, but this time using a numeric value:

cs
[WolverineGet("/age/{age}")]
public static string IntRouteArgument(int age)
{
    return $"Age is {age}";
}

snippet source | anchor

The following code snippet from WolverineFx.Http itself shows the valid route parameter types that are supported at this time:

cs
public static readonly Dictionary<Type, string> TypeOutputs = new()
{
    { typeof(bool), "bool" },
    { typeof(byte), "byte" },
    { typeof(sbyte), "sbyte" },
    { typeof(char), "char" },
    { typeof(decimal), "decimal" },
    { typeof(float), "float" },
    { typeof(short), "short" },
    { typeof(int), "int" },
    { typeof(double), "double" },
    { typeof(long), "long" },
    { typeof(ushort), "ushort" },
    { typeof(uint), "uint" },
    { typeof(ulong), "ulong" },
    { typeof(Guid), typeof(Guid).FullName! },
    { typeof(DateTime), typeof(DateTime).FullName! },
    { typeof(DateTimeOffset), typeof(DateTimeOffset).FullName! }
};

snippet source | anchor

WARNING

Wolverine will return a 404 status code if a route parameter cannot be correctly parsed. So passing "ABC" into what is expected to be an integer will result in a 404 response.

Route Name

You can add a name to the ASP.Net route with this property that is on all of the route definition attributes:

cs
[WolverinePost("/named/route", RouteName = "NamedRoute")]
public string Post()
{
    return "Hello";
}

snippet source | anchor

Released under the MIT License.