nedoto-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Nedoto Typescript Client

MIT Licensed ci

Official Typescript package to connect to Nedoto API.

References:

Installation

Installation with npm:

npm install nedoto-client

Usage

To retrieve your configuration from Nedoto API you should create a new instance of the NedotoClient and then use the Client to retrieve your configuration with the unique configuration slug configured in Nedoto.

The response object is of type Response and with it, you can retrieve the Configuration object.

From the configuration object you can access your configuration value calling the getValue() method.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  const configuration = response.getConfiguration();
  console.log(configuration.getValue()); // will print the value of the Configuration saved in https://app.nedoto.com/configurations
}).catch ((error) => {
  console.error(error);
})

The Nedoto Response

After calling the get() method with the Nedoto client, you'll receive a Response object.

Understand if everything is ok

To understand if everything went fine after retrieving your configuration, you should use the getStatus() method.

It will return a standard HTTP status.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  console.log(response.getStatus()); // ex. 200 HTTP status code
}).catch ((error) => {
    console.error(error);
});

Alternatively you could you use the failed() method that will inform you if there was a failure by returning a boolean value if the HTTP status code is different from 200 (HTTP OK).

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  console.log(response.failed()); // ex. true if HTTP status is different from 200
}).catch ((error) => {
    console.error(error);
});

Understand the errors

After checking if the status of the Response you may want to understand which errors happened during the API request.

For this you could use the getErrors() method.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  console.log(response.getErrors());
}).catch ((error) => {
    console.error(error);
});

the getErrors() method will return an array of reasons explaining why:

[
  'Error message 1',
  'Error message 2',
  'Error message 3',
  // ...
];

Retrieve the Configuration

To retrieve your configuration value you must use the getConfiguration() method.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  const configuration = response.getConfiguration();
  console.log(configuration.getValue()); // will print the value of the Configuration saved in https://app.nedoto.com/configurations
}).catch ((error) => {
    console.error(error);
});

Understand the configuration type

When you define a configuration in Nedoto you must define the type of your configuration.

To retrieve the configuration type you should use the getType() method.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  const configuration = response.getConfiguration();
  console.log(configuration.getType()); // this will print the type of the configuration saved in https://app.nedoto.com/configurations, ex. 'string', 'int', 'json', etc.
}).catch ((error) => {
    console.error(error);
});

Access the creation date?

By using the getCreatedAt() you can access the creation Date of the configuration.

import NedotoClient from 'nedoto-client';

const nedotoClient = new NedotoClient('your-api-key');

nedotoClient.get('your-slug').then((response) => {
  const configuration = response.getConfiguration();
  console.log(configuration.getCreatedAt()); // ex. 2024-02-12T16:09:21+00:00
}).catch ((error) => {
    console.error(error);
});

Want to improve something?

Please feel free to open a PR if you want to improve something on this package.

Package Sidebar

Install

npm i nedoto-client

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

99.2 kB

Total Files

37

Last publish

Collaborators

  • nedoto