Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to perform a batched request in Asp.net core?

We have an API built using ASP.Net Core, and we would like to consolidate multiple requests into one HTTP requests for performance reasons.

In previous versions of asp.net you could allow for batch requests via the DefaultHttpBatchHandler.

Unfortunately, no such thing seems to exist in Asp.net Core.

Is anyone aware of any way to do HTTP batches in core?

like image 347
KallDrexx Avatar asked Dec 07 '16 20:12

KallDrexx


People also ask

How does ASP NET core handle multiple requests?

ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.

How do I make a batch request?

Format of a batch requestA batch request is a single standard HTTP request containing multiple Google Classroom API calls, using the multipart/mixed content type. Within that main HTTP request, each of the parts contains a nested HTTP request. Each part begins with its own Content-Type: application/http HTTP header.

Can we call API in batch?

Batch calls allow API applications to make multiple API calls within a single API call. In addition, each call can be tied to a different access_token meaning batch API calls work with multiple users. Batch calls allow your platform to accomplish more API interaction with less traffic, thus avoiding throttle limits.

How many requests can a .NET core API handle?

Depending on hardware factors with the "weight" of response it may vary from 100 request to 50000 or even more.


2 Answers

After doing my research on the matter, this seems fairly simple to implement. However, I think it should be supported by the official asp.net core team.

To me it seems like it requires a middleware creating multiple RouteContext according to the inputted text, and just invoking their Handlers - and modifying their response. it might be a little bit more difficult, because it would require support for multiple responses for an HttpContext (as far as I know it seems like it will be shared across Controllers).

Anyway, There is an open issue in the official repository that I have risen from the dead, hoping it will move things along. I might work on an implementation in the future if there are no changes soon.

Update

Seems like the asp.net team responded to the request, and created a new issue that is set to 2.0 milestone, so I am guessing this feature will be available during asp.net 2.0 release.

like image 136
gilmishal Avatar answered Oct 05 '22 22:10

gilmishal


Not sure I understand? Do you mean 1 exposed endpoint that makes multiple calls?

Can you not have 1 API action that just creates multiple Tasks (that will run in parallel), waits for them all to complete then return all response data (combined or separated as required)?

like image 24
Mark Redman Avatar answered Oct 06 '22 00:10

Mark Redman