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

mappersmith

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mappersmith

It is a lightweight rest client for node.js and the browser

  • 2.12.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
178K
increased by5.39%
Maintainers
1
Weekly downloads
 
Created

What is mappersmith?

Mappersmith is a lightweight HTTP client library for JavaScript that simplifies the process of making HTTP requests. It provides a declarative way to define API endpoints and offers features like middleware support, request/response transformation, and retries.

What are mappersmith's main functionalities?

Declarative API Definition

Mappersmith allows you to define your API endpoints in a declarative manner. This example shows how to define a client with endpoints for fetching all users and fetching a user by ID.

const { forge } = require('mappersmith');

const api = forge({
  clientId: 'my-api',
  host: 'https://api.example.com',
  resources: {
    User: {
      all: { path: '/users' },
      byId: { path: '/users/{id}' }
    }
  }
});

api.User.all().then(response => console.log(response.data));

Middleware Support

Mappersmith supports middleware, allowing you to intercept and modify requests and responses. This example demonstrates how to log requests and responses using middleware.

const { forge, configs } = require('mappersmith');

configs.middleware = [
  (request) => {
    console.log('Request:', request);
    return request;
  },
  (response) => {
    console.log('Response:', response);
    return response;
  }
];

const api = forge({
  clientId: 'my-api',
  host: 'https://api.example.com',
  resources: {
    User: {
      all: { path: '/users' }
    }
  }
});

api.User.all().then(response => console.log(response.data));

Request/Response Transformation

Mappersmith allows you to transform requests and responses. This example shows how to transform the response to extract user names from the list of users.

const { forge } = require('mappersmith');

const api = forge({
  clientId: 'my-api',
  host: 'https://api.example.com',
  resources: {
    User: {
      all: { path: '/users', transform: (response) => response.data.map(user => user.name) }
    }
  }
});

api.User.all().then(userNames => console.log(userNames));

Retries

Mappersmith provides built-in support for retrying failed requests. This example configures the client to retry failed requests up to 3 times with exponential backoff.

const { forge, configs } = require('mappersmith');

configs.retry = { retries: 3, factor: 2, minTimeout: 1000 };

const api = forge({
  clientId: 'my-api',
  host: 'https://api.example.com',
  resources: {
    User: {
      all: { path: '/users' }
    }
  }
});

api.User.all().then(response => console.log(response.data));

Other packages similar to mappersmith

Keywords

FAQs

Package last updated on 28 Nov 2017

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