javascriptnode.jsexpresshttp

REST API naming conventations for logout


First to say that I am new to coding and I was wondering how should I name my logout route. For example for creating an user, I use this: router.post("/users", async (req, res) => {} For login:router.get("/users", async (req, res) => {}. So what name do I have to use for logout, if the method is method is post?


Solution

  • You should never use verbs like create, get, delete in the URL. To create a user it should simply be like

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

    However for actions other than create, update, delete and get you can treat your resource as controller resource that has executable functions like checkout, start, stop, login etc. The URL will look like

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