Registry / http-networking / mappersmith

mappersmith

JSON →
library2.47.1jsnpmunverified

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.

npm install mappersmith
INSTALL
IMPORT
SIG · MAPPERSMITH
M
mappersmith
http-networkingjavascriptv2.47.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

forge
import forge from 'mappersmith';
import { forge } from 'mappersmith';
Mappersmith's primary client factory is a default export. CommonJS users must access it via `require('mappersmith').default`.
configs
import { configs } from 'mappersmith';
import configs from 'mappersmith';
The global configuration object is a named export. It is used to set global parameters like the default gateway.
Fetch
import Fetch from 'mappersmith/gateway/fetch';
import { Fetch } from 'mappersmith/gateway/fetch';
Specific gateways like `Fetch` are default exports from their sub-paths. CommonJS users should use `require('mappersmith/gateway/fetch').default`.

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()); } });
Debug
Known issues
deprecatedThe `context` argument within custom middleware creation is deprecated and will be removed in future major versions. Developers should update their middleware implementations to use the current API.
fix
Refactor custom middleware to avoid using the `context` argument. Consult the latest documentation for the recommended middleware API, typically relying on `request` and `response` objects directly.
affects: >=2.x
gotchaWhen using Mappersmith with CommonJS, the main `forge` function and specific gateways like `Fetch` are exported as default exports. Directly `require('mappersmith')` or `require('mappersmith/gateway/fetch')` will not provide the expected function/class without appending `.default`.
fix
Always use `require('mappersmith').default` for the `forge` function and `require('mappersmith/gateway/fetch').default` for gateways in CommonJS environments.
affects: >=1.0.0
gotchaMappersmith clients return Promises. Directly accessing properties like `response.data()` on the raw Promise object before it resolves will result in `undefined` or a `TypeError`. You must `await` the response or use `.then()`.
fix
Ensure all Mappersmith client calls are `await`ed or chained with `.then()` to resolve the Promise before accessing response data: `const response = await client.Resource.method(); console.log(response.data());`
affects: >=1.0.0
gotchaThe built-in `Timeout` middleware configures a client-side timeout for the request. This means the client will stop waiting after the specified duration, but the request might still complete on the server, consuming resources. It does not cancel server-side processing.
fix
Understand that `Timeout` middleware is client-side. For server-side request cancellation or resource management, implement corresponding logic within your API's backend.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mappersmith is not a function
Attempting to call the main `mappersmith` module directly as a function in CommonJS, rather than accessing its default export.
fix
Correct the import for CommonJS: `const forge = require('mappersmith').default;`
TypeError: Cannot read properties of undefined (reading 'data')
Attempting to access methods or properties (like `data()`) on the `response` object before the Promise returned by the client call has resolved.
fix
Ensure the client call is `await`ed or chained with `.then()` before accessing response properties: `client.Resource.method().then(response => console.log(response.data()));`
TypeError: (0 , mappersmith_gateway_fetch_1.default) is not a constructor
Attempting to import a gateway (e.g., `Fetch`) as a named export (`import { Fetch } from '...'`) when it is a default export from its specific module path.
fix
Use a default import for gateways: `import Fetch from 'mappersmith/gateway/fetch';`
Mappersmith: [Middleware] 'YourCustomMiddleware' returned an invalid value. Middleware should return a plain object or a Promise that resolves to a plain object.
A custom middleware function did not return a valid `{ request, response }` object (or a subset) or a Promise resolving to such an object, violating the middleware contract.
fix
Review your custom middleware implementation to ensure it always returns a plain object (e.g., `{ request }`, `{ response }`, or both) or a Promise that resolves to such an object.
Upgrade
Version history
2.47.1latest on npm
Audit
Dependencies
diffoptionalUsed by internal debugging or utility features, not essential for core client functionality.
tty-tableoptionalUsed by internal debugging or utility features, not essential for core client functionality.
Agent activity
10 hits · last 30 days
node
8
Resources