I would like to create an API architecture based on REST API. I'm trying to get my head around the basic principles and have not fully understood it yet. Therefore, a number of questions.
- Am I understanding it right?Say I have a resource "users". I could set up a number of URIs like so:
/api/v1/users when called with GET, lists users/api/v1/users when called with POST, creates user record/api/v1/users/1 when called with GET, shows user record when called with PUT, updates user record when called with DELETE, deletes user record/api/v1/roles when called with GET, lists roles/api/v1/roles when called with POST, creates role record/api/v1/roles/1 when called with GET, shows role record when called with PUT, updates role record when called with DELETE, deletes role record/api/v1/permissions when called with GET, lists permissions/api/v1/permissions when called with POST, creates permission record/api/v1/permissions/1 when called with GET, shows permission record when called with PUT, updates permission record- Now, I want to design a REST API that should return full user's information with roles and permissions. Is this Correct?
{GET [/api/v1/users/{userId}/with-roles-permissions]I am expecting below JSON Response:
{"userId": 1,"email": "a@gmail.com","firstName": "a","lastName": "a","roles": [ {"roleId": 1,"roleName": "role","roleDesc": "role desc","permissions": [ {"permissionId": 1,"permissionName": "permission","permissionDesc": "permission desc" } ] } ]}