Package Exports
- node-api-request
- node-api-request/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-api-request) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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);
}
}