SDKs overview
Revolt offers a variety of Software Development Kits (SDKs) and libraries designed to facilitate interaction with its API. These tools enable developers to build custom applications, bots, and integrations that extend the functionality of the Revolt platform. The SDKs abstract the underlying HTTP API requests and responses, providing a more convenient and idiomatic way to develop in different programming languages. This approach streamlines tasks such as user authentication, message handling, channel management, and event processing, allowing developers to focus on application logic rather than low-level networking details. The availability of both official and community-contributed libraries reflects Revolt's open-source nature and developer-centric approach, fostering a broader ecosystem of tools and services built on its platform.
The Revolt API itself is a RESTful interface, accessible via standard HTTP methods, and employs JSON for data exchange. Developers can find comprehensive documentation for the Revolt API reference, detailing endpoints, request formats, and response structures. While direct API interaction is possible, using an SDK is generally recommended for its efficiency and error handling capabilities. SDKs often include features like rate limit handling, WebSocket management for real-time events, and object modeling for API entities, which simplify complex development tasks. For example, a bot might use an SDK to listen for new messages in a channel and respond based on defined keywords, all while the SDK manages the persistent connection to the Revolt server. This design choice aligns with common practices in modern API consumption, as observed in platforms like Stripe's API documentation which also provides extensive SDKs to simplify integration.
Official SDKs by language
Revolt's development team and key community contributors maintain several official SDKs and core libraries. These are typically kept up-to-date with the latest API changes and offer robust functionality for building various applications. The official SDKs aim to provide a consistent and reliable development experience across different programming environments. They usually include comprehensive documentation within their respective repositories and often provide examples to help developers get started. The following table outlines some of the primary official SDKs available for Revolt:
| Language | Package/Library | Install Command | Maturity |
|---|---|---|---|
| JavaScript/TypeScript | revolt.js |
npm install revolt.js |
Stable |
| Python | revolt.py |
pip install revolt.py |
Stable |
| Rust | revolt-rs |
Add revolt-rs = "version" to Cargo.toml |
Beta |
Each of these official libraries is designed to encapsulate the intricacies of WebSocket connections and REST API calls, providing developers with high-level abstractions. For instance, revolt.js for JavaScript and TypeScript environments is widely used for building bots and web-based integrations. It supports both Node.js and browser environments, offering flexibility for different project types. Similarly, revolt.py in Python provides an asynchronous interface, making it suitable for scalable bot applications that need to handle multiple concurrent events. The Rust library, revolt-rs, caters to performance-sensitive applications, leveraging Rust's type safety and concurrency features. Developers can consult the Revolt official documentation for specific version details and API methods available in each SDK.
Installation
Installing Revolt SDKs follows standard package management practices for their respective programming languages. Below are detailed instructions for the most commonly used official SDKs.
JavaScript/TypeScript (revolt.js)
For Node.js projects, revolt.js can be installed via npm or yarn. It is the primary library for building bots and client-side applications with JavaScript or TypeScript.
npm install revolt.js
Or using yarn:
yarn add revolt.js
After installation, you can import the library into your project:
import { Client } from 'revolt.js';
// Or for CommonJS:
// const { Client } = require('revolt.js');
Python (revolt.py)
revolt.py is available on PyPI and can be installed using pip, Python's package installer. It is built for asynchronous operations, aligning with common practices for modern Python network applications.
pip install revolt.py
Once installed, you can import it:
import revolt
Rust (revolt-rs)
For Rust projects, revolt-rs is managed through Cargo, Rust's package manager and build system. You need to add it to your Cargo.toml file.
[dependencies]
revolt-rs = "0.1.0" # Replace with the latest version
Then, Cargo will automatically fetch and compile the library when you build your project. You can then use it in your Rust code:
use revolt_rs::Client;
// ...
It is always recommended to check the Revolt developer documentation for libraries for the most current installation instructions and any specific dependencies or setup procedures required for your environment.
Quickstart example
This example demonstrates how to create a simple Revolt bot using revolt.js that responds to a specific command. This bot will log in, then listen for messages, and if a message starts with !ping, it will reply with Pong!. This illustrates basic client initialization, event handling, and message sending functionalities common in bot development.
JavaScript/TypeScript Bot Quickstart
First, ensure you have revolt.js installed as described in the installation section. You also need a bot token, which can be obtained by creating a bot application on the Revolt developer portal.
import { Client } from 'revolt.js';
// Replace with your actual bot token
const BOT_TOKEN = 'YOUR_BOT_TOKEN_HERE';
const client = new Client();
// Event listener for when the bot is ready and connected
client.on('ready', async () => {
console.log(`Logged in as ${client.user?.username}!`);
});
// Event listener for incoming messages
client.on('messageCreate', async (message) => {
// Ignore messages from other bots to prevent loops
if (message.author?.bot) return;
// Check if the message content starts with '!ping'
if (message.content?.startsWith('!ping')) {
try {
await message.channel?.sendMessage('Pong!');
console.log(`Responded to '!ping' in channel ${message.channel?.name || message.channel?._id}`);
} catch (error) {
console.error('Failed to send message:', error);
}
}
});
// Connect the bot to Revolt
client.loginBot(BOT_TOKEN).catch(console.error);
To run this example:
- Save the code as
index.ts(orindex.jsif not using TypeScript). - Replace
'YOUR_BOT_TOKEN_HERE'with your actual bot token. - If using TypeScript, compile it to JavaScript:
tsc index.ts. - Run the JavaScript file:
node index.js.
This quickstart demonstrates the fundamental components of a Revolt bot: initializing the client, handling the ready event to confirm connection, and processing messageCreate events to implement bot logic. The message.channel?.sendMessage() method is a high-level abstraction provided by the SDK to send messages to a specific channel, without needing to manually construct and send HTTP requests to the /channels/{channel_id}/messages endpoint described in the Revolt API documentation for sending messages.
Community libraries
In addition to the officially maintained SDKs, the Revolt community has developed and contributed numerous libraries and tools across various programming languages. These community-driven projects often cater to specific use cases, offer alternative architectural patterns, or provide bindings for languages not covered by official SDKs. While they might not always have the same level of official support or immediate updates as the core SDKs, they demonstrate the flexibility and extensibility of the Revolt API and the engagement of its developer community.
Examples of community-developed libraries and tools include:
- Go: Libraries like
go-revoltoffer Go language bindings for interacting with the Revolt API, providing a concurrent and performant option for Go developers. - C#: Developers can find C# wrappers, such as
Revolt.NET, which enable .NET applications to integrate with Revolt. - PHP: PHP clients are available for web applications and backend services that require Revolt integration.
- CLI Tools: Various command-line interface tools developed by the community allow for scripting and automation of Revolt tasks without needing to write full applications.
- Framework Integrations: Some community projects focus on integrating Revolt with existing web frameworks or bot frameworks, simplifying development for those ecosystems.
When considering a community library, developers should evaluate its documentation, active maintenance, and community support. Resources like the Revolt developer server and community forums are valuable for discovering these projects, seeking assistance, and contributing to their development. The existence of a vibrant community ecosystem is a strong indicator of a platform's API health and developer engagement, similar to the extensive community contributions seen in other open-source projects documented on Mozilla Developer Network for web technologies.