Harry
Harry

Reputation: 75

How to call the web api recursively in .net core?

I have an endpoint which returns the response containing hotels and a flag which shows more results are available, the client needs to call this endpoint recursively till the time the server returns more results flag as false. What is the better way to implement this? Could anyone help me on this?

Upvotes: 1

Views: 1356

Answers (1)

Manoj Choudhari
Manoj Choudhari

Reputation: 5634

First Option: Avoid It If Possible

Please try to avoid calls on HTTP APIs so as to avoid network latency. This is very important if you want to make multiple calls from a client which is supposed to be responsive.

e.g. if you are developing a web application / WPF application and you want user to click on something which triggers 10-20 calls to API, the operation may not complete quickly may result in poor user experience.

If it is a background job, then probably it multiple calls would make more sense.

Second Option: Optimize HTTP Calls From Client

If you still want to make multiple calls over HTTP, then you will have to somehow optimize the code in such a way that at least you avoid the network latency.

For avoiding network latency, you can bring all the data or major chunk of the data in one call on the client side. Then client can iterate over this set of data.

Even if you reduce half of the calls you buy much more time for client processing.

Another Option

You can also try to think if this can be a disconnected operation - client sending just one notification to server and then server performing all iterations.

Client can read status somewhere from database to know if this operation is complete. That way your client UI would still say responsive and you will be able to offload all heavy processing to Server.

You will have to think and which of these options suits High Level Design of your product/project.

Hope I have given enough food for thoughts (although this may not be solving your issue directly).

Upvotes: 1

Related Questions