1

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?

4
  • Why not use a loop? Commented Jan 15, 2019 at 18:07
  • Recursion or pagination? Commented Jan 15, 2019 at 18:07
  • Um, recursively is a bad idea, however you do want to iterate. Commented Jan 15, 2019 at 18:09
  • 1
    Add an index to the endpoint and have the client iterate. Commented Jan 15, 2019 at 18:13

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

I use microservices and I do not want to hold the user for a long time till the time I get all the hotels, for example, if I am gonna get 100 hotels, I will show those to the user, meanwhile I will process the rest of them... this is what I am thinking to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.