Pete B.
Pete B.

Reputation: 3286

Naming a REST service GET with extensive parameter list

Assume that you are getting some meta-data associated with students, and you are designing a REST web service to do so. Obviously you could do a GET for each student, but you would prefer to get all students at once. Assuming that the ids and the number of students are "too long". That is, that we may be querying 200 students each with an id length of 32 chars, well beyond a safe URL length.

How would you overcome this?

One method is to use a PUT or a POST and pass in a data structure with the student Id's. Which would you choose?

If choosing that method what would you name such a service?

What are some other options?

Upvotes: 0

Views: 42

Answers (1)

Gaurav Arya
Gaurav Arya

Reputation: 146

GET-ting one by one is certainly not a very good solution.

I'd use POST, with the student IDs in a JSON array. Something like

[{"id":"32charstudentId1"},
 {"id":"32charstudentId2"},
 {"id":"32charstudentId3"}]

This is fairly easy to iterate over at the back-end and does the job, just fine. And the response could be something like

[
   {
   "id":"32charstudentId1",
   "meta1":"some info",
    "meta2": "some more info"
   },
   {
   "id":"32charstudentId2",
   "meta1":"some info",
    "meta2": "some more info"
   },
   {
   "id":"32charstudentId3",
   "meta1":"some info",
    "meta2": "some more info"
   }]

The name of the service really depends on what utility it provides to you. To be generic you could simply call it something like "FetchStudentDetails"


A simple array with Student IDs will work just as well, I guess.

An (sort of crude) alternative could be sending sending a POST with student IDs in a string, delimited by a delimiter of your choice, i prefer the semi-colon(;).

Upvotes: 1

Related Questions