Reputation: 1717
Is it RESTful to have HTTP GET /employees/1,2,3,4,5? Or should this be modeled as HTTP GET /employees?id=1,2,3,4,5
Upvotes: 0
Views: 226
Reputation: 130947
This question is more about URI design than REST.
A URI is intended to identify a particular resource in the server. While /employees
identify a collection of employees, a URI like /employees/{id}
should identify an employee with the given id in that collection. The slash expresses hierarchy.
If you want to get multiple resources from that collection (in fact, perform a query in that collection), it makes more sense to use a query parameter. Both approaches are valid:
GET /employees?id=1,2,3,4,5
GET /employees?id=1&id=2&id=3&id=4&id=5
Upvotes: 2
Reputation: 367
I had a simiar requirement to print all the data starting an index and ending with an index, I used query params as below. You can try this.. You can use..
../../employees?start=1&end=5
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getInjectResources(@QueryParam("start") String start,
@QueryParam("end") String end){
String queryParams = "start: "+start+" end: "+end;
// Your logic here..
}
Upvotes: 0