Mappersmith REST Client

2.47.1 · active · verified Tue Apr 21

Mappersmith is a lightweight, isomorphic REST client designed for both Node.js and browser environments, currently stable at version 2.47.1. It streamlines API integration by providing a centralized configuration for all HTTP requests, abstracting away complex network configurations. The library emphasizes a clean, declarative approach to defining API resources and their methods, allowing developers to focus on business logic rather than boilerplate. It supports a robust middleware system for extending client capabilities with features like authentication, retry mechanisms, logging, and error handling. While its release cadence isn't explicitly stated, the high patch version suggests continuous, active development with frequent smaller updates. Its key differentiators include its lightweight nature, isomorphic compatibility, and highly configurable middleware architecture, offering a powerful alternative to more opinionated or heavier HTTP clients.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create a Mappersmith client with the Fetch gateway, define a resource, and make a simple API call to retrieve status data, including error handling.

import forge, { configs } from 'mappersmith';
import Fetch from 'mappersmith/gateway/fetch';

// Configure the Fetch gateway globally
configs.gateway = Fetch;

// Define your API client with resources and methods
const githubStatusClient = forge({
  clientId: 'github-status-api',
  host: 'https://www.githubstatus.com',
  resources: {
    Status: {
      current: { path: '/api/v2/status.json' },
      summary: { path: '/api/v2/summary.json' },
      components: { path: '/api/v2/components.json' }
    },
  },
});

// Make an API call and handle the response
githubStatusClient.Status.current()
  .then((response) => {
    // response.data() contains the parsed JSON body
    console.log('Current GitHub Status Summary:', response.data().status.description);
    console.log('API Request successful.');
  })
  .catch((error) => {
    console.error('Failed to fetch GitHub status:', error);
    if (error.response) {
        console.error('Response status:', error.response.status());
        console.error('Response data:', error.response.data());
    }
  });

view raw JSON →