Reputation: 706
I'm building a social app with the ability of send friend request, confirm request, cancel request, delete friend, and so on. From DB perspective - the friends array is in the 'User' schema. Therefor, these actions are not suitable precisely to DELETE, POST api methods, but to PATCH. But it is a bit weird and unintuitive to make all these action with PATCH...
router.patch( // <============ PATCH
'/send-friend-request',
parseTokenAndPassUser,
userControllers.sendFriendRequest
);
router.patch( // <============ PATCH
'/confirm-friend-request',
parseTokenAndPassUser,
userControllers.confirmFriendRequest
);
router.patch( // <============ PATCH
'/remove-friend',
parseTokenAndPassUser,
userControllers.removeFriend
);
router.patch( // <============ PATCH
'/refuse-friend-request',
parseTokenAndPassUser,
userControllers.refuseFriendRequest
);
router.patch( // <============ PATCH
'/cancel-friend-request',
parseTokenAndPassUser,
userControllers.cancelFriendRequest
);
So what are the suitable methods for that?
In addition, what is the correct REST API method for signin? ( POST is meant to create resources ) ...
thanks
Upvotes: 0
Views: 65
Reputation: 3020
I don't think REST is concerned so much with how the data model is actually implemented at the database level, but rather with resources at a higher level. The HTTP method should reflect the semantics of what you are trying to do with a particular resource, and the url point to the proper resource in the graph.
For instance if you want to delete a friend resource that is a subresource to a user in your resource graph, you want to design a route with:
Upvotes: 1