Playing with public data
Familiarizing yourself with endpoints and entities.
Last updated
Was this helpful?
Familiarizing yourself with endpoints and entities.
Last updated
Was this helpful?
Now that you know how to construct HTTP requests using cURL or your favorite programming language's HTTP utility or library, it is time to learn about endpoints and responses.
All HTTP requests are made against a target URL. When you request data to or from a website, you do so by using a specific URL. Depending on the URL, your request will be interpreted by the HTTP server and the appropriate response will be returned to you.
Examples will be written using the fictional Mastodon website, mastodon.example, which is hosted at https://mastodon.example
. The root of this website is /
, and specific subdirectories and paths are known as endpoints. Mastodon's API endpoints are nested under the /api
namespace, and most methods currently have their endpoints under /api/v1
. Requests will be listed by their HTTP method and their endpoint; for example, GET /api/v1/endpoint should be interpreted as a GET request made to that endpoint on your domain, or in other words, https://mastodon.example/api/v1/endpoint
.
Let's take a look at one of the most basic use cases for public data from Mastodon -- the public timelines.
We can try to request like so:
Wow, that's a lot of text in response! The public timeline returns 20 statuses by default. We can use the limit
parameter to request less than that. Let's try requesting the same endpoint, but with a limit of 2 this time:
Our response should be more manageable this time. We can parse or beautify this JSON with our chosen utility, and we should see that the response looks something like this:
Now that we are familiar with how to make requests and how to handle responses, you can experiment with more public data. The following methods may be of interest:
IDs of accounts and statuses are local to the Mastodon website's database and will differ for each Mastodon website.
One last thing you can do with anonymous requests is to view information about the Mastodon website.
We can do similarly for hashtags by calling -- here, the colon means that this part of the endpoint is a path parameter. In the case of :hashtag, this means we use the hashtag's name (and once again, a limit of 2):
We should once again see 2 statuses have been returned in a JSON array of entities. We can parse the JSON by array, then by object. If we were using Python, our code might look something like this:
is an example of an application that lets you browse public timelines.
Once you know an account's id, you can use to view the entity.
To view public statuses posted by that account, you can use and parse the resulting array of entities.
Once you know a status's id, you can use to view the Status entity.
You can also use to view who boosted that status,
or to view who favourited that status.
Requesting will show you the ancestors and descendants of that status in the tree that is the conversational thread.
If the status has a poll attached, you can use to view the poll separately.
View general information with ,
view its peers with or
its weekly activity with , or to
list all custom emoji available with .
See for a directory of all available profiles.
See for currently trending hashtags.
For a practical example of what you can do with just instance data, see , which lets you preview all custom emoji at a given instance.