简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM