for backend, should i use /users/{id} or /users?userId={id}

tags: learning programming diff-between

content

REST: REpresentational State Transfer

  • REST focuses on resources

/users/{id}

  • direct resource access
  • if it’s id, it means it’s unique, you should just go to that resource
    • that’s what it means by direct resource access
    • usually only 1 resource
  • this is resource identification (it’s a clear and straightforward path)

/users?userId={id}

  • query param is more for searching/filtering
    • the result is a list, potentially more than 1 resource
  • this makes more sense: /coffees?userId={id}
    • this is to search for specific resources associated with userId={id}

Note

this is for backend server routes

up

down

reference