0.7.0 • Published 1 year ago
@interweb/node-api-client v0.7.0
@interweb/node-api-client
@interweb/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 @interweb/node-api-client
Usage
Here's an example of how to use @interweb/node-api-client
:
import { APIClient, APIClientOptions } from '@interweb/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));