REST API Generator
Control your WhatsApp bot remotely via HTTP.
Introduction
WAKit comes with an incredibly powerful built-in plugin: the RESTApiPlugin. When attached to your client, it automatically spins up an Express server with a fully documented REST API.
This means you can trigger WhatsApp messages from your backend (e.g. Django, Laravel, Spring Boot) without needing to write Node.js IPC or messaging queues.
Installation & Setup
Simply import the plugin and install it before you call initialize().
import { WAKitClient } from '@atharvh01/wakit';
import { RESTApiPlugin } from '@atharvh01/wakit/plugins';
const client = new WAKitClient({ sessionName: 'rest-bot' });
// The server will run on port 3000
client.plugins.install(new RESTApiPlugin({ port: 3000 }));
await client.initialize();
Swagger Documentation
Once the server is running, you can view the fully interactive Swagger UI by visiting:
http://localhost:3000/docs
This interface allows you to test the API directly from your browser!
API Endpoints
1. GET /health
Returns the health status of the REST API and the underlying WAKit connection.
Response:
{
"status": "ok",
"clientReady": true,
"uptime": 1420
}
2. POST /api/send
Send a text message to a WhatsApp user or group.
Request Body:
{
"chatId": "1234567890@s.whatsapp.net",
"text": "Hello from the REST API!"
}
Response:
{
"success": true,
"messageId": "3EB0ABCDEF12345"
}
[!WARNING] By default, the REST API is unauthenticated. Ensure you deploy it behind a firewall, VPN, or reverse proxy with authentication if running on a public server!