Registry / api / hapic
library2.8.2jsnpmunverified

hapic is an HTTP API client built on top of axios, designed to simplify interactions with RESTful APIs. Current stable version is 2.8.2, released in September 2024, with monthly releases. It provides features like query building, JSON:API support, pagination, sorting, field selection, and includes relationships. Unlike plain axios or fetch, hapic offers a declarative way to construct complex API requests with type safety through TypeScript. It supports browser and Node.js environments.

npm install hapic
INSTALL
IMPORT
SIG · HAPIC
H
hapic
apijavascriptv2.8.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.

HapicClient
import { HapicClient } from 'hapic'
const HapicClient = require('hapic').HapicClient;
ESM import is preferred; CommonJS require works but may require .default in some setups.
createClient
import { createClient } from 'hapic'
Factory function to create a client instance with default config.
QueryBuilder
import { QueryBuilder } from 'hapic'
import QueryBuilder from 'hapic';
Named export, not default.
default
import hapic from 'hapic'
Default export provides the HapicClient class directly.

Demonstrates creating a client with base URL and auth, then making a GET request with JSON:API query parameters (include, sort, fields, pagination).

import { createClient } from 'hapic'; const client = createClient({ baseURL: 'https://api.example.com', headers: { Authorization: `Bearer ${process.env.API_KEY ?? ''}` } }); async function main() { try { const { data } = await client.get('/users', { params: { include: ['profile', 'roles'], sort: 'createdAt:desc', fields: { users: ['id', 'name'] }, page: { number: 1, size: 10 } } }); console.log(data); } catch (error) { console.error(error); } } main();
Debug
Known issues
gotchaThe client instance is immutable after creation; configuration cannot be changed.
fix
Create a new client with createClient() for each configuration set.
affects: >=2.0.0
deprecatedThe 'transformResponse' option is deprecated in favor of Axios' built-in transformResponse.
fix
Use Axios' transformResponse config directly when creating the client.
affects: >=2.5.0
gotchaQuery parameters like 'include' and 'fields' must be objects or arrays as specified by JSON:API; passing raw strings may cause unexpected behavior.
fix
Always use the appropriate types (e.g., array for include, object for fields).
affects: >=2.0.0
breakingFrom version 2.0.0, the library is ESM-only; CommonJS require() may break.
fix
Use import syntax or set type: 'module' in package.json.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'hapic' or its corresponding type declarations.
Missing TypeScript types or incorrect module resolution.
fix
Ensure you have installed hapic and have 'moduleResolution': 'node' in tsconfig.json.
TypeError: client.get is not a function
Client not created correctly or misimport.
fix
Use createClient() to instantiate the client, then call methods on the returned object.
AxiosError: Request failed with status code 404
Incorrect API endpoint or missing baseURL.
fix
Verify the baseURL and path in the request.
Upgrade
Version history
2.8.2latest on npm
Audit
Dependencies
axiosrequiredUnderlying HTTP client used for making requests.
Agent activity
43 hits · last 30 days
node
38
OpenAI (training)
1
Resources
packagehapic
hapic — npm install hapic · libregistry