To create a new client, you'll need a token for authentication:
const benxApi = require('benxapi');
const request = new benxApi({ urlBase: 'http://api.example.com', token: 'yourToken' });
Sends a GET request to the specified URL.
- Parameters:
url
(string): The API URL.
- Returns:
- A Promise that contains the API response.
request.get('/resource')
.then(response => {
console.log(response);
})
.catch(console.error);
Sends a POST request to the specified URL.
- Parameters:
url
(string): The API URL.options
(object, optional): The data to be sent in the request body.
- Returns:
- A Promise that contains the API response.
request.post('/resource', { key: 'value' })
.then(response => {
console.log(response);
})
.catch(console.error);
The methods throw errors if:
- The
url
parameter is not of typestring
. - The
options
parameter (where required) is not of typeobject
. - No token is provided.