Izumi Kawashima
Izumi Kawashima

Reputation: 1225

What technology is it called to concatenate small (REST) HTTP requests into one HTTP request?

I'm working on a RESTful web service which contains multiple shop information.

There are 100 shops (each shop IDs are not continuous) I want to know the detail, and so I should request them to server, but I don't want to publish 100 GET requests for each shop ID because it's a waste of time and server's connection.

For example, if you want details of shops with ID 3,4,8,16,132,154 and 532, you publish seven requests...

GET /shop/3
GET /shop/4
GET /shop/8
GET /shop/16
GET /shop/132
GET /shop/154
GET /shop/532

Instead, it will be better calling single GET request to some URL like...

GET /shop/3,4,8,16,132,154,532

So ,my questions are

  1. Are there any (well-known) issues using this strategy?
  2. What technology is it called? "Concatenating" or something?

Upvotes: 1

Views: 801

Answers (3)

nategood
nategood

Reputation: 12005

There is no name for the technique within the "REST" nomenclature. Having said that, there are some best practices worth observing.

  1. The URI: A common pattern would be to use a query string and the syntax of repeating the name to express a collection.

/shop/?ids=3&ids=4&ids=8&ids=16&ids=132&ids=154&ids=532

  1. Hypermedia: REST promotes hypermedia. If you are returning a collection of items, it's probably a good idea to include the canonical URIs for the single resources as well in the response. XML has nice conventions of accomplishing this ("href" and "rel" tags), however you can accomplish the same idea in other formats as well (there are even some attempts to formalize such markup).

<shops> <shop href="http://example.com/shop/3" rel="shop"> <name>Shop Three</name> </shop> <shop href="http://example.com/shop/4" rel="shop"> <name>Shop Four</name> </shop> </shops>

Hypermedia makes it easier for humans an machines to navigate your API. It's now clear that this "batch" URL is really a collection of other resources and that those resources can be acted upon individually as well (for PUTs, POSTs, PATCHes, DELETEs, etc.).

Upvotes: 0

noru
noru

Reputation: 526

In OData service(a RESTful service initially defined by Microsoft), they call it "Batch request"

Several requests are sent via http request body, not URL.

As far as I know, it will increase complexity when doing "C" "U" "D" of the CRUD. Cause sometime these requests can tangle together and have heavy dependency with each other. There is a general principal called "All or Nothing" which means you either all success or failed them all to safeguard consistency with some sort of roll back mechanism. But I believe the strategy can be various.

Upvotes: 1

Daniel Scott
Daniel Scott

Reputation: 7961

I don't know if there's a name for the 'strategy', but the variable you supply (3,4,8,16,132,154,532) is a query parameter, and you'd probably write it like this:

GET /shop/?ids=3,4,8,16,132,154,532

Upvotes: 1

Related Questions