@webtender/api-client-node
v0.3.4
Published
WebTender API Client for signing secure REST requests to the WebTender API.
Downloads
12
Maintainers
Readme
WebTender API Client for Node.js
This is a Node JS implementation of WebTender's REST API HTTP Client. You should use this lightweight package to easily start using the API.
If you are NOT using Node.js you can use this package as an implementation example.
You can create your API Key and secret from the API Key Manager in the WebTender Console.
Requirements
Node / Bun or Deno is required to use this package.
ES Module support only (import
not require
.)
We recommend the latest stable version of Node.
- Tested on Node v20.8.0
Minimum requirements:
- Fetch API Node v18.0+
node-fetch may allow for earlier versions
Authentication
WebTender's API uses API keys to authenticate requests along with a HMAC signature (see implementation code.) The signature may be tricky to implement, so we recommend using this package to get started.
The client will automatically look for a local .env
file to get the API key and secret.
Place your API key in a .env
WEBTENDER_API_KEY=your-api-key
WEBTENDER_API_SECRET=your-api-secret
Simply construct
import WebTenderClient from '@webtender/api-client-node';
import dotenv from 'dotenv';
// Load .env
dotenv.config();
const client = new WebTenderClient();
Alternatively use the constructor to pass the API key and secret.
import WebTenderClient from '@webtender/api-client-node';
const client = new WebTenderClient('your-api-key', 'your-api-secret');
Make GET, POST, PATCH, PUT, DELETE requests
The client exposes the following methods to make requests to the API.
client.get(path, params?: Record<string, any>, optionalFetchOptions);
client.post(path, params?: Record<string, any>, optionalFetchOptions);
client.patch(path, params?: Record<string, any>, optionalFetchOptions);
client.put(path, params?: Record<string, any>, optionalFetchOptions);
client.delete(path, params?: Record<string, any>, optionalFetchOptions);
The underlying fetch api is used, you can pass in any valid fetch options as the third argument. For example, to add a custom header.
Example
import WebTenderClient from '@webtender/api-client-node';
import dotenv from 'dotenv';
// Load .env
dotenv.config();
async function listServers() {
const client = new WebTenderClient();
const response = await client.get('v1/servers');
const servers = await response.json();
console.log(servers);
}
listServers();
Testing
You can override the default API endpoint by setting the WEBTENDER_API_BASE_URL
environment variable.
WEBTENDER_API_BASE_URL=https://api.webtender.host/api
Or in your code:
import WebTenderClient from '@webtender/api-client-node';
const client = new WebTenderClient();
client.setBaseUrl('https://api.webtender.host/api');