'Correct REST style for endpoints?
I am trying to create an API. I am worried that the way it works right now though is bad practice. I have an endpoint that accepts get, post, patch, and delete. Is this a poor idea? I was considering replacing my current code:
router.get('/api/user', userController.readUser);
router.post('/api/user', userController.createUser);
router.patch('/api/user', userController.updateUser);
router.delete('/api/user', userController.deleteUser);
With something like:
router.get('/api/getUser', userController.readUser);
router.post('/api/addUser', userController.createUser);
router.patch('/api/updateUser', userController.updateUser);
router.delete('/api/deleteUser', userController.deleteUser);
Which style is most appropriate? Thanks!
Solution 1:[1]
The http method tells people that it's a get, add, update, and delete. You don't need to specify it in the url path.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | James Anderbard |
