beetlex-io / FastHttpApi

a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.
Apache License 2.0
650 stars 175 forks source link

是否支持多种路由匹配? #160

Closed seamusic closed 3 years ago

seamusic commented 3 years ago

原来的方法是可以可以这样支持 [Post(Route = "{code}/{datacode}")] public JsonResult PostStream(IHttpContext context, string code, string datacode = null)

但我现在是想能够支持第二个参数可能会为空的情况,如: api/PostStream/PRJ20210701 api/PostStream/PRJ20210701/0501

当前测试,第一种路径会报 POST /PostStream/PRJ20210701 not found

像asp.net一样: [Route("Everything/MovieCustomer/")] [Route("Everything/MovieCustomer/{movieId}")] [Route("Everything/MovieCustomer/{movieId}/{customerId}")]

beetlex-io commented 3 years ago

组件暂不支持多个Route标签,可以尝试使用组件的Url重写功能

            mApiServer.UrlRewrite.Add("/api/PostStream/{code}/{datacode}", "/api/PostStream");
            mApiServer.UrlRewrite.Add("/api/PostStream/{code}", "/api/PostStream");
beetlex-io commented 3 years ago

更新到V1.9.9

[RouteMap("/map/{code}")]
[RouteMap("/map/{code}/{customer}")]
public object Map(string code, string customer)
{
    return new { code, customer };
}