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:
[WolverineGet("/name/{name}")]
public static string SimpleStringRouteArgument(string name)
{
return $"Name is {name}";
}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:
[WolverineGet("/age/{age}")]
public static string IntRouteArgument(int age)
{
return $"Age is {age}";
}The following code snippet from WolverineFx.Http itself shows the native .NET valid route parameter types that are supported at this time:
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! },
{ typeof(DateOnly), typeof(DateOnly).FullName! }
};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.
Strong Typed Identifiers 5.0
Wolverine.HTTP can support any type as a route argument that implements a TryParse() method. At this point, both the Vogen and StronglyTypedId tools do this for you, and value types generated by these tools are legal route argument variables for Wolverine.HTTP now.
As an example from the Wolverine tests, let's say you have an identity type like this sample that uses StronglyTypedId:
[StronglyTypedId(Template.Guid)]
public readonly partial struct LetterId;You can use the LetterId type as a route argument as this example shows:
[WolverineGet("/sti/aggregate/longhand/{id}")]
public static ValueTask<StrongLetterAggregate> Handle2(LetterId id, IDocumentSession session) =>
session.Events.FetchLatest<StrongLetterAggregate>(id.Value);
// This is an equivalent to the endpoint above
[WolverineGet("/sti/aggregate/{id}")]
public static StrongLetterAggregate Handle(
[ReadAggregate] StrongLetterAggregate aggregate) => aggregate;Route Name
You can add a name to the ASP.Net route with this property that is on all of the route definition attributes:
[WolverinePost("/named/route", RouteName = "NamedRoute")]
public string Post()
{
return "Hello";
}
