0

We have the records in the below format :

[
 {
    id: 1,
    name : 'Chris',
    class : 'x',
    year : 3,
 },
 {
    id: 2,
    name : 'John',
    class : 'y',
    year : 4,
 }
]

I want to fetch multiple records based on id with a single api call.

This could be achieved either by passing multiple ids in a get call or using a post call to post the list of ids.

Get call with multiple ids

GET https://api.com/school/names?id=1,2,3

Post with multiple ids

POST https://api.com/school/names?action=get

request body : 
{
  id1: 1,
  id2: 2,
  id3: 3
}

We don't have issue with the url length as we will not cross the 2048 characters limit.

I see that many public apis use both of the above approaches, I have a feeling that using a POST call to fetch data is against the REST principle.

Could some one suggest what is the best approach for this scenario and the advantage of the approach compared to the other one.

Sathish
  • 101
  • 7
  • [check here](https://stackoverflow.com/q/9371195/681929) comma separated GET request make more sense. – nobalG Jan 06 '23 at 10:45
  • _Usually_ you don't need to really do this. Why is the client fetching those 3? Do they have something in common? A good API will provide a more general endpoint and not let the client build urls. – Evert Jan 06 '23 at 10:53

0 Answers0