3

I am developing an application that will ask the user to type in his Stack Overflow URL, meaning the URL of his Stack Overflow profile,and then get something from the Stack Exchange API.

Is there a canonical form for URL's that represent users?

I ask because my user URL looks like so:

https://stackoverflow.com/users/303685/water-cooler-v2

However, I observe that the last fragment / part of the URL, i.e. the string /water-cooler-v2, which represents my user name, is redundant.

Even if I typed just the following inside a browser, it would redirect my browser to my profile page:

https://stackoverflow.com/users/303685

Notice I removed the URL part /water-cooler-v2. Therefore, I infer that Stack Overflow (and all affiliate sites) need only the user_id, which, in my case, is 303685.

That makes me think. Is there any other URL format that represents a user? Because if there were, I would want my application to be able to parse that to get the user_id, which is the only thing I'd be interested in. Is there an exhaustive list of such URL formats, or are these two that I mentioned just the ones?

2

The shorthand, /u/, works as well: https://stackoverflow.com/u/303685 redirects to your profile.

Note that there's a 'special' user ID: current. This link: https://stackoverflow.com/users/current will automatically redirect to the current user's profile, in the format that you're already familiar with. I think that presenting this link to the user will

  1. make it easier for them to get the URL your application needs
  2. will produce the URL in a consistent format, without having to worry about other variants.
  • Thank you very much. That /me URL is useful for redirecting the user in the case of actual redirects (HTTP 302, 301), but I'd actually just like to parse the URL for the UserId so I can pass it to the StackExchange API for a scenario that does not require authentication. – Water Cooler v2 Nov 14 '17 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .