Reputation: 430
Let's say that the domain structure of anapplication is as follows:
Here is what I think the restful uri designs should be like
The other way to arrive at the above end points would be something like (considering only points 1 and 2) :
/students/{studentid}/papers
and then pass departmentid in the request body. The application would the check for the presence of departmentId in the request. If it's not null then it will assume that this paper is being published for the given departmentid, otherwise for the student himself.
Which one of the above would be a better approach?
Upvotes: 1
Views: 98
Reputation: 202138
This link could help you to design your RESTful service: https://templth.wordpress.com/2014/12/15/designing-a-web-api/.
In addition, here are my comments regarding your URLs:
departmentid
)/students/{studentid}/departments/{departmentid}/papers
will allow to attach an existing paper to a department or create a new one and in addition attach it to the department/students/{studentid}/papers/self
especially the token self
. Does self
refer to the current authenticated user? If so, I think that should use a query parameter since it doesn't really correspond to a resource... In fact, you rather use query parameters for list filteringHope it helps you, Thierry
Upvotes: 1
Reputation:
Since departmentid
is part of how a resources is identified, it must be part of the URL. Putting it into the request body is a violation of REST principles.
Upvotes: 1