How to construct a REST API that takes an array of id's for the resources

uclajatt picture uclajatt · Dec 27, 2010 · Viewed 108.5k times · Source

I am building a REST API for my project. The API for getting a given user's INFO is:

api.com/users/[USER-ID]

I would like to also allow the client to pass in a list of user IDs. How can I construct the API so that it is RESTful and takes in a list of user ID's?

Answer

Florin Dumitrescu picture Florin Dumitrescu · Dec 27, 2010

If you are passing all your parameters on the URL, then probably comma separated values would be the best choice. Then you would have an URL template like the following:

api.com/users?id=id1,id2,id3,id4,id5