RESTful URL for the properties of an entity (How to)

I am designing some restful urls, but I am undecided on how to retrieve an entity of my domain.
At a lower level I have a database with many-to-many and one-to- many relationships.
Let's suppose that the entities are Companies, Groups and Users.
The relationship between Companies and Groups is one-to-many (foreign key in Groups), the same between Companies and Users.
While, between Groups and Users the relationship is many-to-may. My knowledge of restful API tells that I should build urls like:
  • \[code\]http://mywebsite.com/company/\[/code\], \[code\]http://mywebsite.com/company/1/users/\[/code\],\[code\]http://mywebsite.com/company/1/groups/\[/code\] for the post (creation of a new entity) and get methods;
  • \[code\]http://mywebsite.com/company/1\[/code\], \[code\]http://mywebsite.com/company/1/users/1\[/code\],\[code\]http://mywebsite.com/company/1/groups/1\[/code\] for the put (update), delete and get methods;
  • \[code\]http://mywebsite.com/company/1/users/1/groups/\[/code\] for the post (add new associations) and get method.
Now, my problem is how to read(get), (and eventually update(put), or change the company (post)) from a user or a group.
Basically there are 3 options:[*]\[code\]http://mywebsite.com/company/1/users/1/company\[/code\] and provide the same json and xml as \[code\]http://mywebsite.com/company/1\[/code\] and denying repetitive urls like \[code\]http://mywebsite.com/company/1/users/1/company/1/users\[/code\].. [*]nest inside the json and xml of a user description (or of a group) the json and xml of his company, the nested part will be almost the same as \[code\]http://mywebsite.com/company/1\[/code\].But this option implies at each request of a user (or a group)a join between 2 tables, even if I am interested in to know the first name only of a user;[*]provide the foreign key value only (identifier of the company) in the json and xml of the users and groups.What is the best option for you? Why?
 
Back
Top