aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

Direct middleware for http methods #368

Closed neville-nazerane closed 5 years ago

neville-nazerane commented 5 years ago

It would be nice some extension functions for IApplicationBuilder like UseGet() or UseHttpGet() that could add a middleware that directly matches to HTTP GET and to the specified path (similarly for POST, PUT and DELETE). It could be helpful in small web apps for adding some simple middlewares quick and with a high performance. I was planning to make a PR for the same with unit tests and I had to check if this makes sense. I had planned something similar to the following overloads for UseGet(), UsePost(), UsePut() and UseDelete():

  1. UseGet(PathString path, string responseText): On matching the path and method, prints responseText with HTTP OK

  2. UseGet(PathString path, Action<HttpContext> middleware): On matching the path and method, passes the context to middleware.

  3. UseGet(PathString path, Func<HttpContext, Task> middleware): Async variant of the above.

  4. UseGet(PathString path, Func<HttpContext, Func<Task>, Task> middleware): On matching the path and method, passes the context and next delegate to middleware.

Tratcher commented 5 years ago

@JamesNK This looks like Endpoints. Want to show them your progress?

JamesNK commented 5 years ago

That's exactly what we are working on for 3.0.

https://github.com/aspnet/Routing/blob/ede9ff8e50a37053a25076eb767ee7ea46a0f0ea/samples/RoutingSample.Web/UseEndpointRoutingStartup.cs

Disclaimer: This is very early and 3.0 work and will not be RTM until well into next year.

muratg commented 5 years ago

Tracked elsewhere. Closing this one.