0.2.11 • Published 1 year ago

nitrado.js v0.2.11

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 year ago

NOTE This project is not at a stable release, it's still in development. Please report any issues you encounter here.

Setup

NodeJS

Please ensure you have Node 14 or above installed on your system. You can check with node --version. You can use a tool like nvm if you have the incorrect version installed or you can go to the Nodejs website. We recommend Node 16/18.

Installing

Run one of the following commands in your project folder to install nitrado.js

  • npm

    npm install nitrado.js
  • yarn

    yarn add nitrado.js
  • pnpm

    pnpm add nitrado.js

Get Started

Importing

If you are using TypeScript or ESM (import):

import { NitrApi } from 'nitrado.js';

If you are using commonjs (require):

const { NitrApi } = require('nitrado.js');

Authenticating

We recommend storing your API token in a environment variable. The easiest way to do this is by using dotenv. You can however just pass it in as a string.

NOTE Not all endpoints need authentication via token.

You can read the guide here on how to get an API token.

  • dotenv

    const api = NitrApi(process.env['NITRADO_TOKEN']);
  • Passing it in

    const api = NitrApi('REPLACE_ME');

Making requests

The api object has a path function, this is how you can set what path you are making an api request too. Each path might be used for many different requests.

For example lets use the /ping route.

const api = NitrApi();

const ping = api.path('/ping');

When we have the path we can then make a HTTP request to it. For example:

const api = NitrApi();

const response = api.path('/ping').get();

response.then((data) => {
    console.log(data);
});

Becuase nitrado.js is fully type safe, intelli-sense will tell you all the possible paths and HTTP methods you can do!

Param Paths

Some paths might have a parameter, for example the following route has the id parameter: /services/{id}/gameservers/stats.

We can pass that in along side the path function, as always it's fully typesafe so intellisense will tell you what you need to pass in:

api.path('/services/{id}/gameservers/stats', { id: 'REPLACE_ME' });

Passing data into a request

On some endpoints we might need to pass in data to the request, for example the game server details endpoint we saw previously. When we call get on it we can pass in some data.

api.path('/services/{id}/gameservers/stats', { id: 'REPLACE_ME' }).get({
    hours: 24,
});

Getting an API Token

When you are logged into the nitrado website, you can visit the following URL to generate your API token. https://server.nitrado.net/eng/developer/tokens

License

Distributed under the GPL-3.0 License. See LICENSE.txt for more information.

0.2.11

1 year ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.7

2 years ago

0.2.8

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.2.6

2 years ago

0.1.17

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.6

2 years ago

0.1.5-ALPHA

2 years ago

0.1.4-ALPHA

2 years ago

0.1.3-ALPHA

2 years ago

0.1.2-ALPHA

2 years ago

0.1.0-ALPHA.1

2 years ago