1.0.4 • Published 1 year ago
node-api-request v1.0.4
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);
}
}