nedoto-client
v1.0.8
Published
Nedoto Typescript HTTP Client provide access to the Nedoto HTTP APIs
Downloads
19
Maintainers
Readme
Nedoto Typescript Client
Official Typescript package to connect to Nedoto API.
References:
- Nedoto website: https://nedoto.com
- Nedoto app website: https://app.nedoto.com
- Nedoto documentation website: https://docs.nedoto.com
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.