1.0.7 • Published 1 year ago

node-koyeb-api v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Koyeb API Wrapper

This is a Node.js wrapper for the Koyeb API, providing an easy-to-use interface for managing your Koyeb resources programmatically.

Installation

npm install node-koyeb-api

Getting Your Koyeb API Token

Before using this wrapper, you need to obtain an API token from Koyeb. Follow these steps:

  1. Log in to your Koyeb account at https://app.koyeb.com/.
  2. Click on your profile picture in the top right corner and select "Settings" from the dropdown menu.
  3. In the left sidebar, click on "API" under the "Account" section.
  4. Click the "Create API Key" button.
  5. Give your API key a name (e.g., "API Wrapper Access").
  6. Select the appropriate scope for your needs. For full access, choose "Full Access".
  7. Click "Create" to generate your API token.
  8. Copy the displayed token immediately. For security reasons, Koyeb will only show it once.

Keep this token secure and do not share it publicly. You'll use this token to authenticate your requests when using the Koyeb API wrapper.

Usage

First, import the Koyeb class and create an instance with your API token:

const Koyeb = require('node-koyeb-api');
const koyeb = new Koyeb('your-api-token');

API Reference

Apps

Get all apps

const apps = await koyeb.getApps();
console.log(apps);

Get app info

const appInfo = await koyeb.getAppInfo('my-app-name');
console.log(appInfo);

Create a new app

const newApp = await koyeb.createApp('new-app-name', 'App description');
console.log(newApp);

Delete an app

await koyeb.deleteApp('app-to-delete');
console.log('App deleted');

Services

Get all services

const services = await koyeb.getServices();
console.log(services);

Get service info

const serviceInfo = await koyeb.getServiceInfo('service-id');
console.log(serviceInfo);

Redeploy a service

const success = await koyeb.reDeploy('my-app-name');
console.log('Redeployment successful:', success);

Pause a service

await koyeb.pauseService('my-app-name');
console.log('Service paused');

Resume a service

await koyeb.resumeService('my-app-name');
console.log('Service resumed');

Environment Variables

Set an environment variable

await koyeb.setEnv({
  key: 'MY_VAR',
  value: 'my-value',
  serviceName: 'my-app-name'
});
console.log('Environment variable set');

Get all environment variables

const envVars = await koyeb.getAllEnvVars('my-app-name');
console.log(envVars);

Deployments

Get deployments for an app

const deployments = await koyeb.getDeployments('my-app-name');
console.log(deployments);

Create a new deployment

const newDeployment = await koyeb.createDeployment('my-app-name', {
  // deployment definition
});
console.log(newDeployment);

Domains

Get domains for an app

const domains = await koyeb.getDomains('my-app-name');
console.log(domains);

Add a domain to an app

const newDomain = await koyeb.addDomain('my-app-name', 'example.com');
console.log(newDomain);

Remove a domain

await koyeb.removeDomain('domain-id');
console.log('Domain removed');

Logs

Get logs for an app

const logs = await koyeb.getLogs('my-app-name', 100);
console.log(logs);

Other

List activities

const activities = await koyeb.listActivities();
console.log(activities);

Get available regions

const regions = await koyeb.getRegions();
console.log(regions);

Get instances for an app

const instances = await koyeb.getInstances('my-app-name');
console.log(instances);

Error Handling

All methods throw errors if something goes wrong. It's recommended to use try-catch blocks:

try {
  const apps = await koyeb.getApps();
  console.log(apps);
} catch (error) {
  console.error('Error:', error.message);
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago