David Hansen
David Hansen

Reputation: 3187

How to do a RESTful GET on an indefinite number of parameters?

I have a collection of IDs of RESTful resources (all the same type of resource), the number of which can be indefinitely large. I want to make a REST call to get the names of these resources. Something like this:

Send:

['005fc983-fe41-43b5-8555-d9a2310719cd', '4c6e6898-e519-4bac-b03e-e8873d3fa3f0',...]

Receive:

['Resource A', 'Resource B',...]

What is the best way to retrieve the names of these resources RESTfully?

Here are the ideas I have had and the problems I see with each approach:

Is there a better way to do this?

Upvotes: 1

Views: 122

Answers (1)

user1907906
user1907906

Reputation:

Your last approach is RESTful and the one I recommend. I'd do this:

Step 1:

Request:

POST /resource/collection
Content-Tpye: application/json

{
  "ids": [
    "005fc983-fe41-43b5-8555-d9a2310719cd",
    "4c6e6898-e519-4bac-b03e-e8873d3fa3f0"
  ]
}

Response:

201 Created
Location: /resource/collection/89AB8902-FDF1-11E4-ADDF-CD4FB664A5DC

Step 2:

Request:

GET /resource/collection/89AB8902-FDF1-11E4-ADDF-CD4FB664A5DC

Response:

200 OK
Content-Type: application/json

{
  "resources": [ ... ]
}

but then I have to do a 'DELETE /resource/collection/:id' to clean up.

Not, that is not necessary. The server could implement a job that removes all collections that are older than a specific timestamp. It is not the client who has to do this.

If later a client access the collection again, the server would respond with

410 Gone

Upvotes: 1

Related Questions