REST Facade Client

1.16.4 · abandoned · verified Tue Apr 21

rest-facade is a Node.js module designed to simplify the consumption of REST API endpoints by providing a higher-level abstraction over HTTP requests. As of version 1.16.4, it abstracts common CRUD operations (GET, POST, PUT, PATCH, DELETE) and supports dynamic URL parameters using a colon notation (e.g., `:id`). The library offers both Promise-based and callback-based interfaces for asynchronous operations, catering to different coding styles. It differentiates itself by providing a concise client abstraction for specific API paths, aiming to reduce boilerplate when interacting with structured RESTful services. The package's release cadence is effectively dormant, with the last significant update being several years ago.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize a REST client, create a new resource, retrieve it, update it, and finally delete it using the Promise-based API.

const rest = require('rest-facade');

// Create a client for a specific API endpoint with dynamic parameters
const Users = new rest.Client('http://domain.com/users/:id', {
  headers: {
    Authorization: 'Bearer my-auth-token'
  },
  errorFormatter: {
    name: 'error.title',
    message: 'error.text'
  }
});

const newUser = { firstName: 'Jane', lastName: 'Doe' };

// Example: Create a new user
Users.create(newUser)
  .then(function (user) {
    console.log('User created:', user);
    // Example: Get the created user by ID
    return Users.get({ id: user.id });
  })
  .then(function (retrievedUser) {
    console.log('User retrieved:', retrievedUser);
    // Example: Update the user
    return Users.update({ id: retrievedUser.id }, { firstName: 'Janet' });
  })
  .then(function () {
    console.log('User updated successfully.');
    // Example: Delete the user
    return Users.delete({ id: newUser.id });
  })
  .then(function () {
    console.log('User deleted successfully.');
  })
  .catch(function (error) {
    console.error('API operation failed:', error.message || error);
  });

view raw JSON →