批量http请求

发布于 2024-11-16 00:04:03 字数 148 浏览 7 评论 0 原文

有谁知道批量http请求的标准方法? 含义 - 在一次往返中发送多个 http 原子请求?

出于性能原因,我们在 REST API 实现中需要这样的机制。这种机制可以显着减少客户端使用 API 所需执行的往返次数。

预先感谢,

谢伊

Does anyone know a standard way to batch http requests?
Meaning - sending multiple http atomic requests in one round trip?

We need such mechanism in our REST API implementation for performance reasons. This kind of mechanism can reduce dramatically the number of round trips that the client needs to perform to consume the API.

Thanks in advance,

Shay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

静若繁花 2024-11-23 00:04:03

定义包含客户端所需数据的新资源。请参阅http://roy.gbiv。 com/untangled/2008/rest-apis-must-be-hypertext-driven#comment-743

Define a new resource that contains the data the client wants. See http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven#comment-743

断肠人 2024-11-23 00:04:03

有一种官方的 HTTP 方法可以做到这一点,称为 HTTP Pipelined。但浏览器端的问题可能比服务器端的问题更多。因此,如果您仅在客户端具有高级控制权,那么您也许可以使用它。

XHR 并不总是允许管道传输,而且据我所知,您无法使用 Javascript 控制 HTTP 隧道。所以基本的 ajax-jQuery 实现是不存在的。但是您可能会发现 Comet 和 Bayeux 协议有一些高级功能,模拟双向长期 tcp 连接,这肯定会减少 tcp 往返次数。

我不是彗星专家,但您可能会找到有关此的有用信息彗星与HTTP 管道文章,据我了解,其中大部分内容都是高度实验性的,但至少当 HTTP 管道不可用时,您可以使用“经典”comet 进行良好的回退。这可能需要重新标记或提出新问题。

There's an official HTTP way to do that which is called HTTP Pipelining. But you may have more problems with the browser side than with the server-side. So you may be able to use it if you have a hig-level of control on the client side only.

XHR does not always allow pipeling, and AFAIK you have no control of the HTTP tunneling with Javascript. So a basic ajax-jQuery implementation cannot exists. But you may find some advanced things with Comet and the Bayeux protocol, emulating bi-directionnal long-term tcp-connections, where you will certainly reduce the tcp round trips.

I'm not a comet specialist, but you may find useful informations on this Comet & HTTP Pipeling article, to my understanding most of this is highly experimental, but at least you could have a nice fallback with 'classical' comet when HTTP Pipelining is not available. This would maybe need a retag or a new question.

反话 2024-11-23 00:04:03

这是 REST 的问题。它们处于实体级别。 REST 的思想是让每个 URL 唯一地标识一个资源。
当然你可以引入聚合资源。例如,www.yoursite.com/customerA?include=Orders,Faults,Incidents
这会返回 CustomerA 的 XML,同时还会以嵌入集合的形式返回客户的订单、故障和事件。

That's a problem with REST. They are at entity level. The REST idea is to have each URL uniquely identify a resource.
Of course you can introduce aggregated resource. For ex, www.yoursite.com/customerA?include=Orders,Faults,Incidents
This returns the XML for CustomerA but also returns the Orders, faults, Incidents of the customer as embedded collection.

浪菊怪哟 2024-11-23 00:04:03

如果您正在寻找基于 REST 的服务或某种 API。这里有一些标准的开始 http://www. odata.org/documentation/odata-version-3-0/batch-processing/

以及 Google 的实现 https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

If you're looking at REST based services or an API of some kind. There is some beginnings of a standard here http://www.odata.org/documentation/odata-version-3-0/batch-processing/

And an implementation by Google here https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

自我难过 2024-11-23 00:04:03

如果使用 fumanchu 上面所说的专用“聚合”资源对您不起作用,您也可以尝试是否可以将不稳定资源的表示移动到缓存以减少系统负载。例如:“人类”Web 上的 HTML 页面通常包含大量图像,并且许多子请求在那里并不重要。

If using dedicated 'aggregate' resources as fumanchu said above does not work for you, you can also try if you can move representations of less volatile resources to caches to reduce load on your system. For example: HTML pages on the 'human' Web often include loads and loads of images and the many sub request are of no concern there.

变身佩奇 2024-11-23 00:04:03

您可以通过在服务对象上调用 new_batch_http_request() 来创建批量请求,该对象返回 BatchHttpRequest 对象,然后为要执行的每个请求调用 add() 。您可以在每个请求中传递一个回调,并通过对该请求的响应来调用该回调。回调函数参数是每个 API 调用的唯一请求标识符、包含 API 调用响应的响应对象以及可设置为由 API 调用引发的异常的异常对象。添加请求后,您可以调用execute() 来发出请求。 execute() 函数会阻塞,直到调用了所有回调。

参考资料:

您也可以尝试这个 https://developers.google.com/api-client

库/python/guide/batch

https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

You create batch requests by calling new_batch_http_request() on your service object, which returns a BatchHttpRequest object, and then calling add() for each request you want to execute. You may pass in a callback with each request that is called with the response to that request. The callback function arguments are a unique request identifier for each API call, a response object which contains the API call response, and an exception object which may be set to an exception raised by the API call. After you've added the requests, you call execute() to make the requests. The execute() function blocks until all callbacks have been called.

References:

You can try this too https://developers.google.com/api-client

library/python/guide/batch

https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

野生奥特曼 2024-11-23 00:04:03

CURL

Windows 10 的内部版本 17063(及以下版本)附带 CURL 命令:

curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"myname\", \"email\": \"[email protected]\"}' https://example/contact

winHttpJs.bat

call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt

call winhttpjs.bat "http://requestb.in/xxxxxx" -method GET -header hdrs.txt -reportfile reportfile3.txt -saveTo c:\somezip.zip 

call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"  -body-file some.json

目前不支持多部分请求,我打算添加这样的东西,但不知道什么时候有时间。

CURL

The build 17063 of windows 10 (and the following versions) are coming with CURL command:

curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"myname\", \"email\": \"[email protected]\"}' https://example/contact

winHttpJs.bat

call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt

call winhttpjs.bat "http://requestb.in/xxxxxx" -method GET -header hdrs.txt -reportfile reportfile3.txt -saveTo c:\somezip.zip 

call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"  -body-file some.json

It does not support multi-part requests at the moment ,i'm planning to add such a thing but I don't know when i'll have the time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文