I've spent the past few weeks building a RESTful API in PHP (Laravel framework). Also I am building a JavaScript frontend (jQuery / Backbone) that uses this API.
In this API there are some GET requests that require a fair amount of query parameters, most of them are arrays of IDs. I have structured it like this:
/api/cars?colors[]=1&colors[]=3&makes[]=6&makes[]=2&sold=false
(E.g. color with ID=1 is red, make with ID=6 is Audi, etc.)
In PHP the parsing of an array from $_GET['colors'] works out of the box. Also, when I use
$.ajax({
url: "someurl",
method: "GET",
data: {
cars: theCarsArray,
makes: theMakesArray,
sold: false
}
});
Seems to work perfectly as well (the arrays are send in the URL as described above). I am wondering: is this the accepted approach of sending arrays of IDs in a REST interface? Are there any drawbacks to this approach? What are the alternatives?