Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wildcard routing support. #619

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading