Reputation: 1225
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
Upvotes: 1
Views: 801
Reputation: 12005
There is no name for the technique within the "REST" nomenclature. Having said that, there are some best practices worth observing.
/shop/?ids=3&ids=4&ids=8&ids=16&ids=132&ids=154&ids=532
<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
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
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