watchup-monitor-sdk
v1.0.2
Published
JavaScript SDK for the Watchup service.
Readme
Watchup SDK
JavaScript SDK for the Watchup service.
Base API URL: https://watchup-server.vercel.app
Install
npm install watchup-sdkUsage
const { WatchupClient } = require("watchup-sdk");
const client = new WatchupClient({
projectId: process.env.WATCHUP_PROJECT_ID,
apiKey: process.env.WATCHUP_API_KEY,
});
async function main() {
const authResult = await client.login();
console.log(authResult);
}
main();Auth
/sdk/auth is used for login and expects an accurate projectId and apiKey.
const authResult = await client.login({
projectId: "your-project-id",
apiKey: "your-api-key",
});Uptime Monitors
Uptime Monitor service:
- Base URL:
https://watchup-server.vercel.app - Prefix:
/v1
const { WatchupClient } = require("watchup-sdk");
const uptime = new WatchupClient({
baseUrl: "https://watchup-server.vercel.app",
prefix: "/v1",
projectId: process.env.WATCHUP_PROJECT_ID,
apiKey: process.env.WATCHUP_API_KEY,
});
async function main() {
const created = await uptime.createMonitor({
url: "https://example.com/health",
name: "Example",
intervalSeconds: 60,
timeoutMs: 5000,
});
const list = await uptime.listMonitors();
await uptime.deleteMonitor(created.id);
console.log(list);
}
main();Add More Methods
All API calls go through client.request(path, options). To add a new method:
- Identify the API path (for example:
/sdk/something) - Add a method to
WatchupClientinindex.js - Call
this.request("/sdk/something", { method, query, body, headers })
Example method:
class WatchupClient {
async getSomething() {
return this.request("/sdk/something", { method: "GET" });
}
async createSomething(payload) {
return this.request("/sdk/something", { method: "POST", body: payload });
}
}request options:
method: HTTP method, default"GET"query: object converted to URL query stringbody: object is JSON-encoded automaticallyheaders: extra headers merged into the requestprefix: override the instance prefix for this request
Configuration
baseUrl: override the API base URL (defaulthttps://watchup-server.vercel.app)prefix: automatically prepends a path prefix like/v1fetch: provide a customfetchimplementation (useful for tests or older runtimes)
