{"id":47145,"library":"base-api-client","title":"Base API Client","description":"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).","status":"active","version":"1.5.10","language":"javascript","source_language":"en","source_url":"https://github.com/pustovitDmytro/base-api-client","tags":["javascript"],"install":[{"cmd":"npm install base-api-client","lang":"bash","label":"npm"},{"cmd":"yarn add base-api-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add base-api-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"HTTP client used for all requests; bundled as a runtime dependency","package":"axios","optional":false}],"imports":[{"note":"The package exports a single default export (the BaseAPI class). Named destructuring will yield undefined.","wrong":"import { BaseAPI } from 'base-api-client'","symbol":"default","correct":"import BaseAPI from 'base-api-client'"},{"note":"CommonJS require() returns the default export directly.","wrong":"const { BaseAPI } = require('base-api-client')","symbol":"BaseAPI (CommonJS)","correct":"const BaseAPI = require('base-api-client')"},{"note":"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.","wrong":"import type { BaseAPI } from 'base-api-client'","symbol":"TypeScript type import","correct":"import BaseAPI from 'base-api-client'"}],"quickstart":{"code":"import BaseAPI from 'base-api-client';\n\nclass MyAPI extends BaseAPI {\n  constructor(token) {\n    super('https://api.example.com', {\n      timeout: '30s',\n      logger: {\n        log(level, msg) {\n          console[level](msg);\n        }\n      }\n    });\n    this.token = token;\n  }\n\n  getUsers() {\n    return this.get('/users');\n  }\n\n  createUser(data) {\n    return this.post('/users', data);\n  }\n}\n\nconst api = new MyAPI(process.env.API_TOKEN ?? '');\napi.getUsers()\n  .then(response => console.log(response.data))\n  .catch(error => console.error(error));","lang":"typescript","description":"Extends BaseAPI to create a custom API client with a base URL, timeout, and logger. Demonstrates inheritance, constructor configuration, and HTTP methods."},"warnings":[{"fix":"If you need axios v1 in your project, consider overriding via resolutions or pnpm overrides, but be aware of potential API differences.","message":"axios 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.","severity":"gotcha","affected_versions":">=1.0.0 <2.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v1.0.0 or later and pass options as an object. See constructor documentation.","message":"In 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.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"search_vec":"'10':26 '5kb':111 'abstract':9 'across':98 'activ':70 'api':2,5,22,88 'auth':66 'automat':40 'axio':15 'base':1,4,46 'basic':65 'browser':28 'built':11 'bundl':109 'class':10 'clean':81 'client':3,6,23 'configur':48 'creat':20 'crms':92 'custom':62 'definit':77 'delet':39 'depend':17 'e.g':90 'environ':29 'extend':85 'format':52 'frequent':73 'get':35 'gzip':112 'header':63 'http':33 'includ':75 'inherit':82 'interfac':58 'javascript':113 'log':54 'logger':57 'lts':100 'maintain':71 'method':34 'model':83 'ms':51 'multipl':103 'node':99 'node.js':25 'offer':79 'option':53 'packag':68 'patch':38 'platform':104 'post':36 'provid':31 'put':37 'relat':43 'releas':74 'resolut':42 'simplifi':19 'size':110 'small':108 'specif':87 'standard':32 'support':60 'telegram':91 'test':97 'timeout':49 'top':13 'type':21 'typescript':76 'url':41,47 'use':50 'v0.27.x':16 'version':101 'via':55 'well':96 'well-test':95 'wrapper':89","created_at":"2026-06-07T16:50:01.496630+00:00","updated_at":"2026-06-07T16:50:01.496630+00:00","problems":[{"fix":"Run `npm install base-api-client` and use the correct import: `import BaseAPI from 'base-api-client'` (not from a subpath).","cause":"Package not installed or import path wrong.","error":"Error: Cannot find module 'base-api-client'"},{"fix":"Use `import BaseAPI from 'base-api-client'` (default import).","cause":"Attempted to import BaseAPI with named import (e.g., `import { BaseAPI }`) instead of default import.","error":"TypeError: Super expression must either be null or a function"},{"fix":"Ensure the logger has a `.log(level, object)` method. You can use a simple wrapper: `{ log: (level, msg) => console[level](msg) }`.","cause":"The logger object passed in options does not have a `.log` method, or the method is not a function.","error":"TypeError: logger.log is not a function"},{"fix":"Use relative paths (e.g., '/users') that will be resolved against the base URL. Avoid absolute URLs unless intended.","cause":"The URL passed to a method (e.g., this.get) is absolute or misconstructed relative to the base URL.","error":"AxiosError: Request failed with status code 404"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/pustovitDmytro/base-api-client#readme","github":"https://github.com/pustovitDmytro/base-api-client","docs":null,"changelog":null,"pypi":null,"npm":"base-api-client","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}