Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restful Collections - how to either remove OR delete items

Tags:

rest

I read quite some stuff about RESTful API Design. But when it comes to the implementation, it wasn't that easy anymore. I got stuck at the following problem:

Assume the following 2 endpoint:

  1. /api/v1/users/:id
  2. /api/v1/users/1/friends/:id

As we all can see, friends is a collection of the resource user. A user can have n-friends in his friendslist (by standard this would be many to many, but for now, let's assume this to be one to many). Okay, now i want to REMOVE a user (id=3) from the friendslist of user 1 by doing the following HTTP-Request:

DELETE api/v1/users/1/friends/3

And this is where i got stuck - either the request deletes the whole user resource which has id = 3 or removes the resource from the collection. Because both would be valid Restful implementations i think.

So the question is: How to remove an item from the collection without deleting the original resource

I hope that this question is no duplicate - but i did google a lot to find the answer. Maybe i don't know the related technical term to find some pleasing results...

Thanks in forward.

like image 296
Clemens Lackner Avatar asked Sep 06 '25 12:09

Clemens Lackner


1 Answers

The approach to REST looks fine but that really only speaks to path format and HTTP verb. The problem must be in your application code or app routes.

like image 161
errata Avatar answered Sep 09 '25 18:09

errata