Skip to content

Commit

Permalink
Add wildcard routing support.
Browse files Browse the repository at this point in the history
  • Loading branch information
carcer committed Oct 30, 2023
1 parent 6ab3cf6 commit efd7fdc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Http/Wolverine.Http.Tests/route_wildcard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Shouldly;

namespace Wolverine.Http.Tests;

public class route_wildcard : IntegrationContext
{
public route_wildcard(AppFixture fixture) : base(fixture)
{
}

[Fact]
public async Task wildcard()
{
var body = await Scenario(x =>
{
x.Get.Url("/wildcard/one/two/three");
});

body.ReadAsText().ShouldBe("one/two/three");
}
}
2 changes: 1 addition & 1 deletion src/Http/Wolverine.Http/HttpChain.Codegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal IEnumerable<Frame> DetermineFrames(GenerationRules rules)

private string determineFileName()
{
var parts = RoutePattern.RawText.Replace("{", "").Replace("}", "").Split('/').Select(x => x.Split(':').First());
var parts = RoutePattern.RawText.Replace("{", "").Replace("*", "").Replace("}", "").Split('/').Select(x => x.Split(':').First());

return _httpMethods.Select(x => x.ToUpper()).Concat(parts).Join("_").Replace("-", "_").Replace("__", "_");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <auto-generated/>
#pragma warning disable
using Microsoft.AspNetCore.Routing;
using System;
using System.Linq;
using Wolverine.Http;

namespace Internal.Generated.WolverineHandlers
{
// START: GET_wildcard_name
public class GET_wildcard_name : Wolverine.Http.HttpHandler
{
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions;

public GET_wildcard_name(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions) : base(wolverineHttpOptions)
{
_wolverineHttpOptions = wolverineHttpOptions;
}



public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext)
{
var wildcardEndpoint = new WolverineWebApi.WildcardEndpoint();
var name = (string)httpContext.GetRouteValue("name");

// The actual HTTP request handler execution
var result_of_Wildcard = wildcardEndpoint.Wildcard(name);

await WriteString(httpContext, result_of_Wildcard);
}

}

// END: GET_wildcard_name


}

12 changes: 12 additions & 0 deletions src/Http/WolverineWebApi/WildcardEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Wolverine.Http;

namespace WolverineWebApi;

public class WildcardEndpoint
{
[WolverineGet("/wildcard/{*name}")]
public string Wildcard(string name)
{
return name;
}
}

0 comments on commit efd7fdc

Please sign in to comment.