Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Optimize REST API calls

I am in process of building Mash up mobile application. I need to call my API Provider and integrate with Facebook , twitter etc. During this process, I have to make multiple REST API calls one after other to same domain(with different path and query parameters ofcourse). Also the API calls has to be sequential as in result of one is required to call the next. What are the ways I can optimize these http calls to avoid the round trip. Suggestions for java and js is welcome

like image 514
randomness Avatar asked Oct 05 '13 04:10

randomness


People also ask

How do you increase performance of API call?

Another way to improve the performance of your API calls is by sending and receiving only the portion of the data that you're interested in. This lets your application avoid transferring, parsing, and storing unneeded fields, so it can use resources including network, CPU, and memory more efficiently.

How do you optimize rest APIs for scalability?

Make each REST resource is a small entity. Don't read data from join of many tables. Always keep data sources as much as near by because these blocks will make server resources (CPU) ideal and it no other request can use that resource while it is ideal.

How optimize API call react?

now you can do as many get req using the getData method even updating the state and error is handled you just need to pass your setState method just make sure to return cancelRequests function in useEffect that will cancel all api requests made by getData.


2 Answers

The requirements stated are broad. Since you are using the public third party API, that somewhat limits the scope of possible optimizations. There is absolutely nothing that you can do to speed up the APIs as they do not belong to you.

In general I suggest following guidelines which will help you come up with better application.

  1. Thumb rule is make as few API calls as possible.
  2. Making fewer network calls (resulting from API calls) will imply that the device radio (which is used to communicate with the server over the air) will be less frequently used and hence less power required.
  3. Now, making fewer number of calls may not be an option always. So study the public API documentation carefully and make sure you know the all the details of the APIs you need.
  4. For example, there could be an API which gives details of an entity upon passing its identifier. If you need the details of 5 such entities then there should be an API which takes a bunch of IDs and returns all the details at once. This way you save multiple calls.
  5. Caching is very effective way of reducing the number of API call. So look for any data received from server which can be cached for certain duration.
  6. Note that caching would need more memory and hence make sure you are aware of its implication and accordingly decide the amount of data that needs to cached.
  7. Apart from memory, the data can be cached on the disc as well, which will help reduce the memory usage. Not sure if you are using Android, please refer to this related post.

On the side note, you can refer to following links which offer general guidelines for developing a mobile App.

  1. Make your application blazing fast.
  2. Optimizing a Mobile App for Mobile network.

Please note that these are general guidelines. Some may not apply to your particular use case.

like image 172
Santosh Avatar answered Sep 21 '22 15:09

Santosh


If you need the results of the first API call in order to make the next API call, then there is nothing you can do client-side to avoid a sequential round-trip for each one. There would either need to be an existing API call that can be used to combine multiple calls into one or you would need to add such an API call to the server or you would need to use a proxy server that does that on your behalf.

If you don't need the results of the first API call in order to make the next API call, but you just want to process the results in sequential order, then you can make all the API calls at once and structure your response code to process them in order (saving any results that arrive out of order for later processing).

like image 26
jfriend00 Avatar answered Sep 19 '22 15:09

jfriend00