lornhp13

1.0.0 • Public • Published

RestClient

RestClient is a simple yet powerful package for making HTTP requests to RESTful APIs from Node.js applications.

Installation

You can install RestClient via npm:

npm install @username/rest-client

Usage

const RestClient = require('@username/rest-client');

const client = new RestClient('https://api.example.com');

(async () => {
  try {
    const response = await client.get('/users');
    console.log(response);
  } catch (error) {
    console.error('Error:', error.message);
  }
})();

Creating a Client

To create a new REST client, simply instantiate the RestClient class with the base URL of your API:

const client = new RestClient('https://api.example.com');

Making Requests

RestClient supports common HTTP methods like GET, POST, PUT, and DELETE. Here's how you can use them:

// GET request
const response = await client.get('/endpoint');

// POST request with a JSON payload
const response = await client.post('/endpoint', { key: 'value' });

// PUT request
const response = await client.put('/endpoint', { key: 'updated value' });

// DELETE request
const response = await client.delete('/endpoint');

License

This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

none

Package Sidebar

Install

npm i lornhp13

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.01 kB

Total Files

3

Last publish

Collaborators

  • henryhupper123