Reputation: 4345
Let's say I have the following model
Course
Student
The URI:
/courses/1
should return the following information about a particular course:
Name
Number
Date
Instructor
and: /courses
should return a list of above mentioned information.
I'm not sure about the 'return' part. If this was a JAX-WS service we would get the information about the course in question, create XML, stick that XML into a SOAP envelope and XML over HTTP to the client.
Also in a 'normal' web application, in response to:
/courses
A List<Course>
would be request.addAttribute(-)
'd to the JSP to render an HTML table. What is supposed to happen for a RESTful web service? Should the contents of the List
be directly written to the output stream?
Upvotes: 1
Views: 1823
Reputation: 18174
In RESTful Web Services you define what will be the output. It can be a plain text, JSON, HTML, XML or whatever you would like. The RESTful endpoint is able to produce what you like (what you define in the @Produces
annotation).
Basically, you get what you serve, so if you invoke a GET request on your RESTful resource which serves HTML - you'll get rendered HTML page. If it serves the XML - you'll get XML, just like in SOAP Web Services.
You can use the same semantics you used for SOAP Web Services. So if someone hits the /courses
link, you could return whole list of courses (i.e. in a JSON format).
This could be useful for future references: Jersey User Guide
Upvotes: 2