Registry / devops / base-api-client

base-api-client

JSON →
library1.5.10jsnpmunverified

Base API client is an abstract class built on top of axios (v0.27.x dependency) that simplifies creating typed API clients in Node.js (>=10) and browser environments. It provides standard HTTP methods (get, post, put, patch, delete), automatic URL resolution relative to a base URL, configurable timeout (using ms format), optional logging via a logger interface, and support for custom headers and basic auth. The package is actively maintained with frequent releases, includes TypeScript definitions, and offers a clean inheritance model for extending into specific API wrappers (e.g., Telegram, CRMs). It is well-tested across Node LTS versions on multiple platforms and has a small bundle size (~5KB gzipped).

npm install base-api-client
INSTALL
IMPORT
SIG · BASE-API-CLIENT
B
base-api-client
devopsjavascriptv1.5.10
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.

default
import BaseAPI from 'base-api-client'
import { BaseAPI } from 'base-api-client'
The package exports a single default export (the BaseAPI class). Named destructuring will yield undefined.
BaseAPI (CommonJS)
const BaseAPI = require('base-api-client')
const { BaseAPI } = require('base-api-client')
CommonJS require() returns the default export directly.
TypeScript type import
import BaseAPI from 'base-api-client'
import type { BaseAPI } from 'base-api-client'
TypeScript users should import as a value (default export) because the class is both a value and a type. Use `import BaseAPI from 'base-api-client'` which will bring both the type and the runtime.

Extends BaseAPI to create a custom API client with a base URL, timeout, and logger. Demonstrates inheritance, constructor configuration, and HTTP methods.

import BaseAPI from 'base-api-client'; class MyAPI extends BaseAPI { constructor(token) { super('https://api.example.com', { timeout: '30s', logger: { log(level, msg) { console[level](msg); } } }); this.token = token; } getUsers() { return this.get('/users'); } createUser(data) { return this.post('/users', data); } } const api = new MyAPI(process.env.API_TOKEN ?? ''); api.getUsers() .then(response => console.log(response.data)) .catch(error => console.error(error));
Debug
Known issues
gotchaaxios is a runtime dependency — it will be installed with base-api-client. Ensure your project's axios version is compatible (v0.x). The package does not use axios v1.x yet.
fix
If you need axios v1 in your project, consider overriding via resolutions or pnpm overrides, but be aware of potential API differences.
affects: >=1.0.0 <2.0.0
gotchaThe timeout option uses ms format (strings like '1m', '30s'). If you pass a number, it will not be interpreted correctly; you must pass a string or a number in milliseconds (integer). The documentation states it is cast to integer, but only strings in ms-format are supported.
fix
Always pass timeout as a string in ms format (e.g., '5000') or as an integer in milliseconds (e.g., 5000) — but note that numbers are not explicitly documented as supported. Safer to use strings.
affects: >=1.0.0
gotchaThe logger interface must have a .log(level, object) method. If you pass a logger that expects different arguments (e.g., debug only), the internal calls will fail silently or produce errors.
fix
Make sure your logger object has a .log method that accepts a level (string) and an object (any). For simple logging, you can use console.
affects: >=1.0.0
breakingIn version 1.0.0, the constructor signature changed from (url, options) to (url, options) with the second argument being an object. Earlier alpha versions may have had different signatures.
fix
Upgrade to v1.0.0 or later and pass options as an object. See constructor documentation.
affects: <1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'base-api-client'
Package not installed or import path wrong.
fix
Run `npm install base-api-client` and use the correct import: `import BaseAPI from 'base-api-client'` (not from a subpath).
TypeError: Super expression must either be null or a function
Attempted to import BaseAPI with named import (e.g., `import { BaseAPI }`) instead of default import.
fix
Use `import BaseAPI from 'base-api-client'` (default import).
TypeError: logger.log is not a function
The logger object passed in options does not have a `.log` method, or the method is not a function.
fix
Ensure the logger has a `.log(level, object)` method. You can use a simple wrapper: `{ log: (level, msg) => console[level](msg) }`.
AxiosError: Request failed with status code 404
The URL passed to a method (e.g., this.get) is absolute or misconstructed relative to the base URL.
fix
Use relative paths (e.g., '/users') that will be resolved against the base URL. Avoid absolute URLs unless intended.
Upgrade
Version history
1.5.10latest on npm
Audit
Dependencies
axiosrequiredHTTP client used for all requests; bundled as a runtime dependency
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
base-api-client — npm install base-api-client · libregistry