Home > OS >  Correct REST style for endpoints?
Correct REST style for endpoints?

Time:03-23

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!

CodePudding user response:

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.

  • Related