Registry / devops / apisauce

apisauce

JSON →
library3.2.2jsnpmunverified

apisauce is a lightweight wrapper around axios (^1.7) that standardizes API responses and error handling. Version 3.2.2 is current, with moderate release cadence. Key differentiators: all responses follow a single flow with a `problem` property for error classification, built-in request/response transforms, connection detection on React Native, and full TypeScript support. It simplifies client code by always resolving promises, avoiding try/catch for network errors.

npm install apisauce
INSTALL
IMPORT
SIG · APISAUCE
A
apisauce
devopsjavascriptv3.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

create
import { create } from 'apisauce'
const create = require('apisauce').create
ESM import is preferred. CommonJS require works but named export destructuring is required.
apisauce (default)
import apisauce from 'apisauce'
var apisauce = require('apisauce')
Default import includes all exports. CommonJS require returns an object with named exports.
ApisauceInstance type
import type { ApisauceInstance } from 'apisauce'
For TypeScript, use `import type` to avoid runtime overhead.
APIResponse type
import type { APIResponse } from 'apisauce'
const { APIResponse } = require('apisauce')
APIResponse is a type, not a runtime value. CommonJS require will cause 'APIResponse is not a constructor' error.

Creates an API instance with base URL and headers, makes a GET request, and handles both success and failure using the ok property.

import { create } from 'apisauce' const api = create({ baseURL: 'https://api.github.com', headers: { Accept: 'application/vnd.github.v3+json' }, timeout: 10000 }) async function getCommitMessage() { const response = await api.get('/repos/infinitered/apisauce/commits/HEAD') if (response.ok) { console.log(response.data.commit.message) } else { console.error('Error:', response.problem) } } getCommitMessage()
Debug
Known issues
breakingapisauce v3 drops default export; use named export `create`.
fix
Replace `import apisauce from 'apisauce'` with `import { create } from 'apisauce'`.
affects: >=3.0.0
breakingapisauce v3 requires axios >= 1.0.0. Axios 0.x is not compatible.
fix
Upgrade axios to ^1.7. Version 2.0.0 of apisauce used axios ^0.21.
affects: >=3.0.0
deprecatedThe `monitor` and `transformRequest` options are deprecated in v3. Use `onRequest` and `requestTransform` instead.
fix
Replace `monitor: fn` with `onRequest: fn` and `transformRequest: fn` with `requestTransform: fn`.
affects: >=3.0.0
gotchaThe `problem` property is a string enum, not a custom object. Common values: 'CLIENT_ERROR', 'SERVER_ERROR', 'NETWORK_ERROR', 'TIMEOUT_ERROR', 'CANCEL_ERROR'.
fix
Check response.problem against these string values.
affects: >=1.0.0
gotchaIf you pass a custom axios instance via `axiosInstance`, the baseURL and headers from apisauce config are ignored.
fix
Set baseURL and headers on the axios instance before passing it to create().
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: apisauce_1.default is not a function
Importing default export after v3 which only exports named exports.
fix
Use `import { create } from 'apisauce'` instead of `import apisauce from 'apisauce'`.
Cannot find module 'axios'
axios is a peer dependency and must be installed separately.
fix
Run `npm install axios` or `yarn add axios`.
TypeError: response.ok is not a function
Treating response.ok as a function (e.g., response.ok()) instead of a boolean property.
fix
Use `if (response.ok)` not `if (response.ok())`.
Error: Request failed with status code 404
The default behavior of apisauce is to resolve all responses, but if you use axios interceptors that reject, the error may propagate.
fix
Ensure no external axios interceptors are rejecting promises. apisauce catches errors internally.
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies
axiosrequiredPeer dependency: apisauce is a wrapper around axios, requiring axios to be installed
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
apisauce — npm install apisauce · libregistry