twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
524 stars 83 forks source link

Using with minimal API #90

Closed ErenKrt closed 2 years ago

ErenKrt commented 2 years ago

Hello, im trying use on my minimal api on net 6.0. I cant figure out, i tried some things but not work. Anybody know working way ?

twitchax commented 2 years ago

Can you give some sample code that isn't working?

ErenKrt commented 2 years ago

Hello again, when i tried access to "HttpProxyAsync" cant find any method because this extension of BaseController. Minimal API not using controller then i added app.UseProxies its working but swagger cant find endpoint of proxies and i needed that. My endpoint like that;

app.MapGet("test", async (HttpContent ctx) =>
{
   // I Cant figure what i need write
   // return ctx.HttpProxyAsync("http://example.com"); 
   // My expectation like this. I couldn't find anything about usage with minimal api on your wiki.
});
twitchax commented 2 years ago

I see. We just need to expose an extension method for that. Adding now.

delasource commented 2 years ago

"Minimal API" is a totally new approach from Microsoft, starting in .net6.0. You should really implement this, as it is a very very fast api framework. (which is not done by just implementing an interface method, to my knowledge)

twitchax commented 2 years ago

@delasource, the performance improvements in .NET 6 apply across the board, regardless of whether or not you use minimal API.

Minimal API does two primary things, as far as I can tell:

  1. Reduces cognitive overhead of creating controller-based APIs since controller-based APIs tend to have more boilerplate code, and
  2. Somewhat reduces the dependency footprint when using only minimal APIs.

In this case, this fix addressed (1). This library can be used in a minimal API context now.

It does not address (2), but I would love to see the data on what, exactly, the dependency footprint delta is.

From a performance standpoint, it should be the same as long as I add net6.0 as a target, which I can do fairly quickly. I will add this to the next release.