6

With web services it is considered a good practice to batch several service calls into one message to reduce a number of remote calls. Is there any way to do this with RESTful services?

1
  • 1
    foreach(RestRequest req in requestBatch) requestResponseList.Add(webService.Call(req)); What do you mean by batch calling a RESTful service? One request that contains many request definitions? Commented Sep 20, 2008 at 21:02

5 Answers 5

5

If you really need to batch, Http 1.1 supports a concept called HTTP Pipelining that allows you to send multiple requests before receiving a response. Check it out here

Sign up to request clarification or add additional context in comments.

2 Comments

Agreed - plus HTTP supports keep alive so with HTTP pipelining and keep alive you get the effect of batching while using the same REST API - there's usually no need for another REST API to your service
We do this and it works beautifully. No need for extraneous endpoints with awkward multiplicities. We use org.apache.http.nio.protocol.HttpAsyncRequestExecutor and their SSLNHttpClientConnectionFactory on the client. Our weblogic server supports it out of the box.
4

I don't see how batching requests makes any sense in REST. Since the URL in a REST-based service represents the operation to perform and the data on which to perform it, making batch requests would seriously break the conceptual model.

An exception would be if you were performing the same operation on the same data multiple times. In this case you can either pass in multiple values for a request parameter or encode this repetition in the body (however this would only really work for PUT or POST). The Gliffy REST API supports adding multiple users to the same folder via

POST /folders/ROOT/the/folder/name/users?userId=56&userId=87&userId=45 

which is essentially:

PUT /folders/ROOT/the/folder/name/users/56 PUT /folders/ROOT/the/folder/name/users/87 PUT /folders/ROOT/the/folder/name/users/45 

As the other commenter pointed out, paging results from a GET can be done via request parameters:

GET /some/list/of/resources?startIndex=10&pageSize=50 

if the REST service supports it.

1 Comment

What if you were to create a GetBatch operation that takes as a parameter, a collection of REST operations to be performed, and their parameters. Then, a set of the results could be returned, keyed by the REST operation to which it correlates? Would this also violate the conceptual model of REST?
3

I agree with Darrel Miller. HTTP already supports HTTP Pipelining, plus HTTP supports keep alive letting you stream multiple HTTP operations concurrently down the same socket to avoid having to wait for the responses before streaming new requests to the server etc.

So with HTTP pipelining and keep alive you get the effect of batching while using the same underlying REST API - so there's usually no need for another REST API to your service

Comments

3

The team with Astoria made good use of multi-part mime to send a batch of calls. Different from pipelining as the multi-part message can infer the intent of an atomic operation. Seems rather elegant.

Comments

-1

Of course there is a way but it would require server-side support. There is no magical one size fits all methodology that I know of.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.