Skip to content

A simple module that makes it easier to query data from an API.

Notifications You must be signed in to change notification settings

BENx2115/benxapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

Creating a Client

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' });

Methods

get(url)

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);

post(url, options = {})

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);

Error Handling

The methods throw errors if:

  • The url parameter is not of type string.
  • The options parameter (where required) is not of type object.
  • No token is provided.

About

A simple module that makes it easier to query data from an API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published