0

is it possible to enumerate all instances of a resource without voilating rest principles in a single call.

Say I want to enumerate all the student information using one call.

GET /students

With REST principles this call is returning:

"students": [{
   "uri":"/student/1"
},
{
   "uri":"/student/2"

},
]

What I want is to use a single call to get all the data:

GET /student

 "students": [{     
  "name":"x",    
   "moreInfo":...,
  "uri":"/student/1"
 },
 {    
  "name":"y",   
  "moreInfo":...,
  "uri":"/student/2" 
 }, ]
rawjean
  • 51
  • 4
  • Please include your code. It would be especially useful to show us how a student is mapped to JSON. It looks like only the `uri` property is serialized. –  Oct 24 '13 at 08:20
  • I know you didn't ask this question, but have you considered [HAL](http://stateless.co/hal_specification.html) instead of the custom media type you're using? It gives you a very nice way to not only separate links from your object structure but also an option to embed the objects. – Jonathan W Oct 31 '13 at 15:42

1 Answers1

2

This would not violate HTTP principles. Whether it is a good idea or not though is a question for your resource hierarchy, based on what you are trying to do. Such a setup would have a students resource that holds the data for all students. There would be no need then for an individual student record (eg GET /students/:id). The client might get annoyed if this returned a huge amount of data though, and it is pushing the processing of the data onto the client. Say the client only wants one student. It has to parse the entire student population, ignoring all the irrelevant data, to get to the one student it wants. Of course if the client needs all the student data then this isn't an issue.

So really the issue is not how RESTful this is, but why you want to do it and whether it is the right thing for the client of your system. What hierarchy is the client expecting. If this fits then by all means go for it.

Cormac Mulhall
  • 1,197
  • 1
  • 8
  • 12