O'Reilly logo

RESTful Web Services Cookbook by Subbu Allamaraju

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.12. When to Tunnel Multiple Requests Using POST

Combining several HTTP requests in a single HTTP request to support batch processing is not an uncommon technique. Here is a commonly used implementation of this technique:

  1. The client serializes each HTTP request (including the URI, HTTP method name and HTTP headers) into a JSON object or an XML document or even a single part in a multipart/mixed message.

  2. The client creates an envelope format to combine each of those requests into a single message.

  3. The client submits that message to the server using POST to a resource that is often termed a batch end point.

  4. The server, on receiving this message, opens the envelope, reconstructs HTTP requests, and then dispatches them to the respective URIs on the server. Alternatively, the server may bypass HTTP and dispatch these requests directly to the code that can process those requests.

  5. The server collects the response for each request and then serializes them into a single message and returns to the client.

  6. The client opens the envelope and processes each response message.

Here is an example:

# Batch request
POST /batch HTTP/1.1 1
Host: www.example.org
Content-Type: application/xml;charset=UTF-8

<batch-request>
  <request method="PUT" uri="http://www.example.org/req/2009/11/1/log"> 2 <headers> <header name="Content-Type" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required