1

Possible Duplicate:
Rest URL design - multiple resources in one http call

I have looked for answers on this site and the net, but haven't quite figured out the best way to approach this problem.

As an example, say I have the following REST API

Single resource REST API is straightforward:

/car/{id} --> get car by an id

Multiple resource get for a list of cars:

/cars;ids={id1,id2,id3 etc} --> get list of cars by ids

/cars;list-id={listId};count=5 --> get cars defined by a list id saved in the cloud

/cars;relatives={id};count=5 --> get cars that are related to the car specified by id

A list-id can specify an arbitrary list of elements to return. /cars will just return cars defined in that list.

Note: the matrix params relatives, ids, and list-id cannot all be used in a single GET request. E.g if ids and list-id both appear, then ids will take priority.

Question: Should this be redesigned? And if so, how? Thanks.

Community
  • 1
  • 1
  • 1
    this might be helpful http://stackoverflow.com/questions/969585/rest-url-design-multiple-resources-in-one-http-call – hvgotcodes Oct 03 '11 at 02:16
  • Marc, Why isn't the question also getting merged? This isn't an identical question but an embellishment of the above question (BTW, the link isn't very descriptive). – Paul Morgan Oct 03 '11 at 11:50
  • Well, this gives me a little more food for thought, but it also seems that the current design I have in place isn't really a RESTful web design? Thanks for that link. – KnowledgeSeeker777 Oct 08 '11 at 23:49

1 Answers1

1

What if you view a car as a list ID with just one car? A list ID could then refer to one car or multiple cars. For this to work a list ID and a car ID have to share the same 'domain'. One doesn't take priority over the other because they are actually the same thing - a list of cars.

GET /car/{id} could be one car or a list of cars.

GET /car/{id}/related would return a list of those cars related to the list of cars in the car ID. But this list would have no ID of it's own (yet).

POST /car/{id}/related would return a list ID for the list of cars. That could then be used with GET /car/{id} to return the same list of cars that was also retrieved indirectly with GET /car/{id}/related.

Paul Morgan
  • 31,226
  • 3
  • 24
  • 27