Mastodon API client for JavaScript, TypeScript, Node.js, browsers
npm i masto --save
This is a simple example which creates a new status:
import Masto from 'masto';
(async () => {
const masto = await Masto.login({
uri: 'https://example.com', // URL of your instance
accessToken: 'YOUR TOKEN', // Your access token (optional)
});
const data = await masto.createStatus({
status: 'Hello Mastodon!',
visibility: 'direct',
});
console.log(data);
})()All of available methods / interfaces are described in the documentation. You can also refer the examples on this repository.
- Browsers and Node.js are both supported
- TypeScript powers static typing.
- You don't need to type API URLs because each endpoints have their own function
- Detailed docs and rich hovering menu for IDE, provided by TSDoc
- AsyncIterator makes timeline pagination easier.
A. Masto.js using AsyncIterator which is very new JS feature and it may not be supported in particular environments. So in browsers, you need to use a polyfill like Babel's. In Node.js, it is supported on v10 so you can update and use it.
If you're using Masto.js with TypeScript, you need to add the following config to tsconfig.json for static typing.
{
"compilerOptions": {
"lib": [
+ "esnext.asynciterable"
...
