Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.63 KB

File metadata and controls

50 lines (38 loc) · 1.63 KB

@constructive-io/node-api-client


Node.js API Client

@constructive-io/node-api-client is a lightweight and flexible HTTP client for interacting with RESTful APIs in Node.js. It supports common HTTP methods such as GET, POST, PUT, PATCH, and DELETE, with customizable options for headers, query parameters, and timeouts.

install

npm install @constructive-io/node-api-client

Usage

Here's an example of how to use @constructive-io/node-api-client:

import { APIClient, APIClientOptions } from '@constructive-io/node-api-client';

const options: APIClientOptions = {
  restEndpoint: 'http://localhost:8001/api'
};

const client = new APIClient(options);

// GET request
client.get('/endpoint')
  .then(response => console.log(response))
  .catch(error => console.error(error));

// GET request with query params
client.get('/endpoint', { search: 'value' })
  .then(response => console.log(response))
  .catch(error => console.error(error));

// POST request with JSON body
client.post('/endpoint', null, { key: 'value' })
  .then(response => console.log(response))
  .catch(error => console.error(error));