Designing URI for current logged in user in REST applications
<p>I need a URI in my REST API to retrieve the current logged in user. Usually I use <a href="https://www.rfc-editor.org/rfc/rfc7231#section-4.3.1" rel="noreferrer"><code>GET</code></a> on resource with ID, but the client doesn't know the ID of the user.</p>
<p>I found the following solutions:</p>
<ul>
<li><p>By user name</p>
<p>This solution uses the user name instead of the ID of the user.</p>
<p>Example:</p>
<ul>
<li><a href="https://developer.atlassian.com/static/rest/bitbucket-server/4.5.1/bitbucket-rest.html#idp2837072" rel="noreferrer">Bitbucket REST API</a>: <code>GET /user/{userSlug}</code></li>
</ul>
</li>
<li><p>With own resource</p>
<p>This solution has one resource for users and one additional resource for logged in user.</p>
<p>Examples:</p>
<ul>
<li><p><a href="https://docs.atlassian.com/jira/REST/latest/#api/2/myself-getUser" rel="noreferrer">JIRA REST API</a>: <code>GET /myself</code></p>
</li>
<li><p><a href="https://developer.github.com/v3/users/#get-the-authenticated-user" rel="noreferrer">GitHub REST API</a>: <code>GET /user</code></p>
</li>
<li><p><a href="https://api.stackexchange.com/docs/me">Stack Exchange REST API</a>: <code>GET /me</code></p>
</li>
</ul>
</li>
<li><p>With symbolic link</p>
<p>This solution has a symbolic link for the ID of the user.</p>
<p>Example:</p>
<ul>
<li><a href="https://docs.atlassian.com/confluence/REST/5.4.4/#d2e90" rel="noreferrer">Confluence REST API</a>: <code>GET /user/current</code></li>
</ul>
</li>
<li><p>With filter</p>
<p>This solution uses a filter for the user name.</p>
<p>Example:</p>
<ul>
<li><a href="https://docs.atlassian.com/jira/REST/latest/#api/2/user-getUser" rel="noreferrer">JIRA REST API</a>: <code>GET /user?username={username}</code></li>
</ul>
</li>
</ul>
<p>Which one is most RESTful? What are the pros and cons?</p>