如何优化REST API调用 [英] How to Optimize REST API calls

查看:95
本文介绍了如何优化REST API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Mash up移动应用程序。我需要调用我的API提供程序并与Facebook,Twitter等集成。在此过程中,我必须一个接一个地对同一个域(具有不同的路径和查询参数)进行多个REST API调用。 API调用也必须是顺序的,因为需要调用下一个调用。有什么方法可以优化这些http调用以避免往返。欢迎对java和js的建议

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

推荐答案

所述要求很广泛。由于您使用的是公共第三方API,这在某种程度上限制了可能的优化范围。绝对没有什么可以加速API,因为它们不属于你。

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规则尽可能少地进行API调用

  2. 减少网络呼叫(由API调用产生)将意味着设备无线电(用于通过无线方式与服务器通信)将减少经常使用,因此需要更少的电力。

  3. 现在,总是可以选择减少呼叫次数。因此,仔细研究公共API文档,确保您了解所需API的所有详细信息。

  4. 例如,可能有一个API在传递其标识符时提供实体的详细信息。如果你需要5个这样的实体的细节,那么应该有一个API,它接受一堆ID并一次返回所有细节。这样您保存多个电话

  5. 缓存是减少API调用次数的非常有效的方法。因此,请查找从服务器收到的任何可以缓存一段时间的数据。

  6. 请注意,缓存需要更多内存,因此请确保您了解其含义并相应地确定需要缓存的数据。

  7. 除内存外,数据也可以缓存在光盘上,这有助于减少内存使用量。不确定您是否使用Android,请参阅此相关帖子

  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. 申请炽热快速

  2. 优化适用于移动网络的移动应用

  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.

这篇关于如何优化REST API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆