Git Product home page Git Product logo

nitrado.js's Introduction

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

Table of Contents
  1. Setup
    1. NodeJS
    2. Installing
  2. Get Started
    1. Importing
    2. Authenticating
    3. Making Requests
    4. Param Paths
    5. Passing data into a request
  3. Getting an API token
  4. Support
  5. License

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. We recommend Node 16/18.

Installing

Run the following command in your project folder to install nitrado.js

npm install 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.

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(process.env['NITRADO_TOKEN']);

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

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

const api = NitrApi(process.env['NITRADO_TOKEN']);

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}/bouncers.

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}/bouncers', { id: 'REPLACE_ME' });

Passing data into a request

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

api.path('/services/{id}/bouncers', { id: 'REPLACE_ME' }).delete({
    ident: 'REPLACE_ME',
});

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

Support

License

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

nitrado.js's People

Contributors

cainthebest avatar actions-user avatar dependabot[bot] avatar ghostdevv avatar

Stargazers

ahhoushh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.