Search code examples
restrestful-url

REST API Design, RESTful API Naming Conventions


I have resource Draft which has the following representation:

{
   "name": "name",
   "groups": ["group1", "group2"] 
}

I need to design endpoint which would allow to add new groups to groups.

For instance, lets say client wants to modify the resource above by adding two new groups: group3 and group4, then, after this operation, the resource should look like:

{
   "name": "name",
   "groups": ["group1", "group2", "grpoup3", "group4"] 
}

I'm not sure what should be the right URL structure and HTTP method for such operation.

Currently I'm considering the following option:

PATCH `/draft/groups/add` 

{
    'groups': ["group3", "group4"]
}

However, I'm not quite sure if that's the right choice.

Any help would be appreciated,

Thanks


Solution

  • Seems like you're identifying your draft by its name, and you have several groups in each draft. If that's correct, then this would be the REST Naming Convention:
    POST /drafts/{draftName}/groups/ HTTP/1.1 - to create;
    PUT /drafts/{draftName}/groups/{groupId} HTTP/1.1 - to update;
    GET /drafts/{draftName}/groups/{groupId} HTTP/1.1 - to get (groupId shouldn't be required in case of collection resource request).