Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my experience, <code>GET /users/{id} GET /users/email/{email}</code> is the most common approach. I would also expect the methods to return a 404 Not Found if a user doesn't exist with the provided <code>id</code> or <code>email</code>. I wouldn't be surprised to see <code>GET /users/id/{id}</code>, either (though in my opinion, it is redundant).</p> <h2>Comments on the other approaches</h2> <ol> <li><code>GET /users/id={id} GET /users/email={email}</code> <ul> <li>I don't think I've seen this, and if I did see it, it would be very confusing. It's almost like it's trying to imitate query parameters with path parameters.</li> </ul></li> <li><code>GET /users?id={id} GET /users?email={email}</code> <ul> <li>I think you hit the nail on the head when you mentioned using query parameters for filtering.</li> <li>Would it ever make sense to call this resource with <em>both</em> an <code>id</code> and an <code>email</code> (e.g. <code>GET /users?id={id}&amp;email={email}</code>)? If not, I wouldn't use a single resource method like this.</li> <li>I would expect this method for retrieving a <em>list</em> of users with optional query parameters for filtering, but I would not expect <code>id</code>, <code>email</code> or any unique identifier to be among the parameters. For example: <code>GET /users?status=BANNED</code> might return a list of banned users.</li> </ul></li> </ol> <p><sub>Check out <a href="https://stackoverflow.com/a/4028874/1671856">this answer</a> from a related question.</sub></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload