Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batching in REST

Tags:

rest

wcf

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?

like image 792
alex Avatar asked Sep 20 '08 20:09

alex


2 Answers

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

like image 55
Darrel Miller Avatar answered Oct 25 '22 00:10

Darrel Miller


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.

like image 23
davetron5000 Avatar answered Oct 25 '22 00:10

davetron5000