Note that there are some explanatory texts on larger screens.

plurals
  1. POREST - supporting multiple possible identifiers
    text
    copied!<p>For the site I am working on, we are in the process of improving our URLs for one type of resource - specifically, moving away from numerical IDs toward unique, descriptive strings. A similar example would be switching from identifying users by numerical database ID to identifying them by username (not our specific case, but analagous). So a URL to access a user's information used to look like:</p> <pre><code>/users/48573 </code></pre> <p>And now it looks like</p> <pre><code>/users/thisisausername. </code></pre> <p>The only problem is that we still need to be able to fetch them through numerical IDs somehow, for legacy consumers of the API. We don't need the REST URLs themselves to redirect (e.g. <code>/users/48573</code> should not redirect to <code>/users/thisisausername</code>), we just need a method to obtain the right data using the old identifier. The solution should either provide an alternate way of accessing the user information (which conveniently includes the new identifier, username) by ID, or of accessing just the username by ID. Some possible solutions might be:</p> <ul> <li>Using a node to specify some alternate method of identification, e.g. <code>/users/byid/48573</code></li> <li>Using a query parameter to specify some alternate method of identification, e.g. <code>/users/48573?fetchby=id</code> or <code>/users/48573?byid=true</code></li> <li>Treating username-by-id as another resource, e.g. <code>/identifiers/username/48573</code></li> </ul> <p>Which of these (if any) is closest to proper REST? How would you deal with the problem?</p>
 

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