Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于注销的REST API命名约定_Javascript_Node.js_Express_Http - Fatal编程技术网

Javascript 用于注销的REST API命名约定

Javascript 用于注销的REST API命名约定,javascript,node.js,express,http,Javascript,Node.js,Express,Http,首先,我要说的是,我是一个新的编码,我想知道我应该如何命名我的注销路线。例如,对于创建用户,我使用以下方法: router.post(“/users”),异步(req,res)=>{} 对于登录:router.get(“/users”),async(req,res)=>{}。那么,如果方法是method is post,那么注销时我必须使用什么名称?您可以为路由使用任何您想要的名称,只需使用能够理解发生了什么的命名 比如说 router.post("/user/create"

首先,我要说的是,我是一个新的编码,我想知道我应该如何命名我的注销路线。例如,对于创建用户,我使用以下方法:
router.post(“/users”),异步(req,res)=>{}

对于登录:
router.get(“/users”),async(req,res)=>{}
。那么,如果方法是method is post,那么注销时我必须使用什么名称?

您可以为路由使用任何您想要的名称,只需使用能够理解发生了什么的命名

比如说

router.post("/user/create", async (req, res) => {}
router.post("/user/login", async (req, res) => {}
router.post("/user/logout", async (req, res) => {}
您还可以将相同的名称用于不同的http方法

router.post("/user" , ... ) 
router.get("/user" , ... )
router.delete("/user" , ... )  

这些都将分别被视为不同的…

您可以对路线使用任何您想要的名称,只需使用命名,您就可以了解发生了什么

比如说

router.post("/user/create", async (req, res) => {}
router.post("/user/login", async (req, res) => {}
router.post("/user/logout", async (req, res) => {}
您还可以将相同的名称用于不同的http方法

router.post("/user" , ... ) 
router.get("/user" , ... )
router.delete("/user" , ... )  

这些都将分别被视为不同的…

您不应该在URL中使用诸如create、get、delete之类的动词

router.post("/user", async (req, res) => {}
但是,对于创建、更新、删除和获取以外的操作,您可以将资源视为具有签出、启动、停止、登录等可执行功能的控制器资源

router.post("/user/login", async (req, res) => {}
router.post("/user/logout", async (req, res) => {}

你不应该在URL中使用像create、get、delete这样的动词

router.post("/user", async (req, res) => {}
但是,对于创建、更新、删除和获取以外的操作,您可以将资源视为具有签出、启动、停止、登录等可执行功能的控制器资源

router.post("/user/login", async (req, res) => {}
router.post("/user/logout", async (req, res) => {}