Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rest-facade

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-facade

Simple abstraction for consuming REST API endpoints

  • 1.16.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
230K
increased by6.82%
Maintainers
1
Weekly downloads
 
Created

What is rest-facade?

The rest-facade npm package is a lightweight library that simplifies the process of making RESTful API calls. It provides a facade over HTTP requests, making it easier to interact with REST APIs by abstracting away the complexities of handling HTTP methods, headers, and responses.

What are rest-facade's main functionalities?

Creating a REST client

This feature allows you to create a REST client that can be used to interact with a RESTful API. The `Client` class takes the base URL of the API as a parameter.

const { Client } = require('rest-facade');
const api = new Client('https://api.example.com');

Making GET requests

This feature allows you to make GET requests to a specified endpoint. The `get` method returns a promise that resolves with the response data or rejects with an error.

api.get('/resource').then(response => console.log(response)).catch(error => console.error(error));

Making POST requests

This feature allows you to make POST requests to a specified endpoint with a payload. The `create` method sends the payload to the server and returns a promise that resolves with the response data or rejects with an error.

api.create('/resource', { key: 'value' }).then(response => console.log(response)).catch(error => console.error(error));

Handling headers

This feature allows you to include custom headers in your requests. The headers can be specified as an option in the request method.

api.get('/resource', { headers: { 'Authorization': 'Bearer token' } }).then(response => console.log(response)).catch(error => console.error(error));

Error handling

This feature provides a way to handle errors that occur during the request. The promise returned by the request method can be caught to handle any errors.

api.get('/resource').then(response => console.log(response)).catch(error => console.error('Error:', error.message));

Other packages similar to rest-facade

Keywords

FAQs

Package last updated on 30 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc