When Should You Use Path Variable and Query Parameter?

Query Parameter

/users?id=123 # Fetch a user who has id of 123 

Path Variable

/users/123 # Fetch a user who has id 123

When should you use Path Variable, and how about Query Parameter?

/users # Fetch a list of users
/users?occupation=programer # Fetch a list of programer user
/users/123 # Fetch a user who has id 123
/users [GET] # Fetch a list of users
/users [POST] # Create new user
/users/123 [PUT] # Update user
/users/123 [DELETE] # remove user

Wrapping up

References

--

--

Senior Front End Architect / Freelance, self-employed

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store