Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading