Search code examples
phpapirestful-url

RESTful API Path design guideline


I am wondering for a restful API, which of the following would be more practical?

  1. myapi.com/users/{userid}
  2. myapi.com/users?userid={userid}

I am just confused when we should pass parameter in the URL Param vs. the Path.


Solution

  • Params are used to filtering a query:

    http://www.acme.com/products/?filter=cats&sort=des
    

    And path are used to get an element:

    http://www.acme.com/products/1234
    

    So, I recommend you to use myapi.com/users/{userid}.

    Jump to slide 60 from this great presentation (that I recommend you to read).