Node API Request
Node-API-Request is a versatile and lightweight module designed to streamline the process of making HTTP requests in Node.js. Whether you're fetching data from APIs, downloading resources, or interacting with web services
Installation
To install the package, use the following command:
npm install --save node-api-request
Initialization
You can initialize the Node-API-Request using either CommonJS or ES6 syntax:
// CommonJS
const NodeApiRequest = require("node-api-request");
// ES6
import NodeApiRequest from 'node-api-request';
Usage
import NodeApiRequest, { RequestOptions, ApiResponse } from 'node-api-request';
async function main() {
const apiUrl = 'https://jsonplaceholder.typicode.com/todos/1';
const requestOptions: RequestOptions = {
url: apiUrl,
method: 'GET',
};
try {
const response: ApiResponse = await NodeApiRequest.sendRequest(requestOptions);
console.log('Response Status:', response.status);
console.log('Response Body:', response.body);
} catch (error) {
console.error('Error:', error);
}
}