2

I am building a web application that makes use of multiple API's (Google Maps, Weather APIs, and more). I am using Python + Flask on the backend, and Javascript (probably with React, I have not decided yet) on Front end.

The application will take the results of these various API query's and then give the user a simple, summarized result, which involves a fair amount of calculations and conditional logic based on the API response.

What the best practice to do this?

If I do all the API calls on the client side, and I deal with calculations and such there too, that feels cumbersome.

If I do it all on the backend, the calls are not asyncronous and so I am worried the calls might take a while. Though in my use case a 2-3 second wait is probably acceptable as long as there is a "Loading" message. This is what I currently have (halfway through writing all the API calls and the needed calculations)

I could also do the API calls on the client, pass it to the server for calculations, and then sent the results back to the front end. Not sure if that's a practical solution or if it would really solve anything.

  • 2
    API calls can be asynchronous on server side as well – Fabio Jun 25 '18 at 5:58
  • How so? Is that possible using Python and Flask? I'm sure it's possible with some other languages but that's not what I'm doing here. – Brian C Jun 25 '18 at 6:20
  • Though in my use case a 2-3 second wait is probably acceptable as long as there is a "Loading" message then what's worrying you? – Laiv Jun 25 '18 at 6:20
  • 1. "Probably acceptable" is still far from ideal. I want to cut down the wait as much as possible. 2. It could be even longer than that, which is not acceptable – Brian C Jun 25 '18 at 6:22
  • 1
    sounds all very theoretical. Did you get any evidence that you "already" need to improve something that was not yet implemented? – Laiv Jun 25 '18 at 6:24
2

You should be using a server to manage and call external APIs then combine the responses as necessary and return them to the client.

  • You shouldn't be hijacking your clients resources to call all these services and process results depending on how intensive it is. You also don't know what kind of connection your client has, what takes you a few seconds on a good connection could be significantly longer.
  • You can't guarantee your client can access all the various API endpoints which requires more work to fallback gracefully. Corporate environments are a good example where this is common.
  • You may be able to take advantage of caching some calls across users.

The general goal should be to minimize the number of requests and amount of data transferred. Third party requests should also be minimized unless they can reduce the amount of data transferred or provide similar benefit (ie CDNs).

  • If the 3rd party endpoints need a kind of auth token, managing the 3rd party calls on the server side would also ensure confidentiality. – Cardin Jan 11 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.