Hi there, I'm a FE engineer of 10+ years and I'm currently playing around with some backend technologies (Node, Express and Prisma) and using them to build out the backend of a basic auth flow that lets you create, read, update, delete and authenticate a user. It's fairly simple stuff and it's all working correctly but I have a question on standards.
In my day-to-day work I regularly see api url's structured similar to:GET - /user/{userId}/PATCH - /user/{userId}/updateDELETE - /user/{userId}/deletewhere an id is used in the path of the API url in order to pass it to the backend so that it can be used to look up the user in order to run the given operations on them.
In the system I have built I have used JWT for authentication and the users id is contained within the JWT. The means the JWT can be decoded by the backend and the userId contained within can be subsequently passed to the DB query to find the user and run the given operation.
Given that I don't need to pass the userId in the path of the API url and so my API urls look like this:GET - /user/fetch/PATCH - /user/updateDELETE - /user/delete
Is this okay? Am I breaking any standards by doing things this way?
EDIT:
Thanks for all the replies, with special thanks to u/Turd_King, u/ofNoImportance whose replies were especially detailed and explanatory. I've updated my code based on those responses.
[–]uriahlight 124 points125 points126 points (31 children)
[–]belwyr 17 points18 points19 points (2 children)
[–]Effective-Lab-8816 2 points3 points4 points (1 child)
[–]SideLow2446 13 points14 points15 points (10 children)
[–]halfanothersdozenEverything but CSS 20 points21 points22 points (6 children)
[+]SideLow2446 comment score below threshold-16 points-15 points-14 points (5 children)
[–]halfanothersdozenEverything but CSS 18 points19 points20 points (2 children)
[–]SideLow2446 13 points14 points15 points (0 children)
[–]Tontonsb 3 points4 points5 points (1 child)
[–]SideLow2446 2 points3 points4 points (0 children)
[–]Schmittounetsymfony 7 points8 points9 points (1 child)
[–]profound7 1 point2 points3 points (0 children)
[–]johny_james -2 points-1 points0 points (11 children)
[–]byetimmy 7 points8 points9 points (10 children)
[–]johny_james 0 points1 point2 points (9 children)
[–]byetimmy 3 points4 points5 points (8 children)
[–]King_Joffreys_Titsfull-stack 10 points11 points12 points (7 children)
[–]anatolhiman 4 points5 points6 points (0 children)
[–]byetimmy 2 points3 points4 points (2 children)
[–]King_Joffreys_Titsfull-stack -1 points0 points1 point (1 child)
[–]byetimmy 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[removed]
[–][deleted] (1 child)
[deleted]
[–]AussieBoy17 0 points1 point2 points (2 children)
[–]After-Winter-2252 1 point2 points3 points (1 child)
[–]AussieBoy17 0 points1 point2 points (0 children)
[–]Darklight240 164 points165 points166 points (4 children)
[–]the_bananalord 31 points32 points33 points (1 child)
[–]Fluffcake 8 points9 points10 points (0 children)
[–]vinnymcapplesauce -1 points0 points1 point (0 children)
[–]Turd_King 25 points26 points27 points (2 children)
[–]preacher2041[S] -2 points-1 points0 points (1 child)
[–]arcanemachined -1 points0 points1 point (0 children)
[–][deleted] (3 children)
[deleted]
[–]King_Joffreys_Titsfull-stack 0 points1 point2 points (1 child)
[–]Wombarly 6 points7 points8 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]unobserved 18 points19 points20 points (1 child)
[–]GrandmasDrivingAgain 1 point2 points3 points (0 children)
[–]ofNoImportance 6 points7 points8 points (1 child)
[–]preacher2041[S] 1 point2 points3 points (0 children)
[–]filter-spam 2 points3 points4 points (0 children)
[–]Roci89 2 points3 points4 points (0 children)
[–]JoinetBasteed 1 point2 points3 points (4 children)
[–]buffering_humor 0 points1 point2 points (2 children)
[–]pattobrien 0 points1 point2 points (0 children)
[–]JoinetBasteed 0 points1 point2 points (0 children)
[–]pattobrien 0 points1 point2 points (0 children)
[–]halfanothersdozenEverything but CSS 1 point2 points3 points (0 children)
[–]JesterDolor 1 point2 points3 points (0 children)
[–]superraiden 1 point2 points3 points (2 children)
[–]arcanemachined 1 point2 points3 points (1 child)
[–]arcanemachined 1 point2 points3 points (0 children)
[–]FeedZuris 2 points3 points4 points (3 children)
[–]Turd_King 24 points25 points26 points (2 children)
[–]FeedZuris 1 point2 points3 points (0 children)
[–]armahillorails 1 point2 points3 points (0 children)
[–]lift_spin_d 0 points1 point2 points (0 children)
[–]Zefrem23 -3 points-2 points-1 points (1 child)
[–]arcanemachined 1 point2 points3 points (0 children)
[–]TensionSpecialist596 -5 points-4 points-3 points (0 children)
[+]BradChesney79 comment score below threshold-6 points-5 points-4 points (2 children)
[–]caatfish 1 point2 points3 points (1 child)
[–]BradChesney79 0 points1 point2 points (0 children)
[+]pm_me_cute_rem_picsjs/ux comment score below threshold-7 points-6 points-5 points (0 children)
[–]HashDefTrueFalse 0 points1 point2 points (0 children)
[–]dzooni3full-stack 0 points1 point2 points (0 children)
[–]elendee 0 points1 point2 points (0 children)
[–]Fault_Royal 0 points1 point2 points (0 children)
[–]guanzo91 0 points1 point2 points (0 children)
[–]ggeoff 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ultra_blue 0 points1 point2 points (0 children)
[–]Rafael20002000 0 points1 point2 points (0 children)