mastodon / mastodon

Your self-hosted, globally interconnected microblogging community
https://joinmastodon.org
GNU Affero General Public License v3.0
46.87k stars 6.93k forks source link

Add well-known support for API discoverability #30862

Open tobiastom opened 3 months ago

tobiastom commented 3 months ago

Pitch

It would be nice to be able to find the endpoint of the API, not by hardcoding it into the domain, but with a .well-known resource.

If I'm developing a client, and the user would enter example.com into the domain, my client could request https://example.com/.well-known/mastodon.json and find something like this:

{
    "api" {
            "v1": "https://example.com/my/sub-directory/mastodon/v1/"
    }
}

This is just an example, I have no feelings about the structure of this file, as long as the API endpoint is discoverable.

Motivation

From what I could find there is no way to offer the mastodon API behind some base url. The common practice seems to be a separate sub-domain and the hard-coded API endpoint. My proposal would allow the API to be placed inside an arbitrary directory.

Please keep in mind that this should only affect the API. I'm not proposing to run the mastodon frontend and everything included with it inside a sub-directory.

tobiastom commented 3 months ago

From what I see, this might be related to https://github.com/mastodon/mastodon/issues/23939 as it could also serve as a detection mechanism.

trwnh commented 3 months ago

You could also do this with a link relation, but the bigger issue behind this and other related issues is that the Mastodon API is not standardized. I'd love to see clients support a variable base URI so that you can have more than one API on the same application, not just be resigned to hardcoding /api to point at Mastodon-like API implementations.