Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch http requests

Tags:

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

like image 978
Shay Tsadok Avatar asked Jun 17 '11 00:06

Shay Tsadok


People also ask

What is HTTP batch request?

A batch request is a single standard HTTP request containing multiple Compute Engine API calls, using the multipart/mixed content type. Within that main HTTP request, each of the parts contains a nested HTTP request. Each part begins with its own Content-Type: application/http HTTP header.

How do I send a batch request?

A batch request consists of multiple API calls combined into one HTTP request, which can be sent to the batchPath specified in the API discovery document. The default path is /batch/ api_name / api_version . This section describes the batch syntax in detail; later, there's an example.

How can multiple requests be executed in a batch request?

Batching is a way of combining multiple requests into a single HTTP request. The requests are combined in a single JSON payload, which is sent via POST to the \$batch endpoint.

Can we call API in batch?

Batch calls allow API applications to make multiple API calls within a single API call. In addition, each call can be tied to a different access_token meaning batch API calls work with multiple users. Batch calls allow your platform to accomplish more API interaction with less traffic, thus avoiding throttle limits.


2 Answers

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

like image 89
fumanchu Avatar answered Oct 13 '22 03:10

fumanchu


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.

like image 38
regilero Avatar answered Oct 13 '22 05:10

regilero