Skip to main content

Package Managers

CallApi is available on npm and can be installed using any modern package manager.
npm install @zayne-labs/callapi

Package Information

Package Name

@zayne-labs/callapi

Bundle Size

Under 6KB gzipped

Dependencies

Zero dependencies

License

MIT License

CDN Usage

For quick prototyping or simple projects, you can use CallApi directly from a CDN:
<script type="module">
  import { callApi, createFetchClient } from "https://esm.run/@zayne-labs/callapi";
  
  const { data } = await callApi("/api/users");
  console.log(data);
</script>
CDN usage is great for prototyping but not recommended for production. Use a package manager for better performance and reliability.

Runtime Requirements

CallApi requires a JavaScript runtime with native Fetch API support:
1

Browsers

All modern browsers support the Fetch API:
  • Chrome 42+
  • Firefox 39+
  • Safari 10.1+
  • Edge 14+
Internet Explorer is not supported. Use a polyfill if you need to support older browsers.
2

Node.js

Node.js 18.0.0 or higher is required:
node --version
# v18.0.0 or higher
Node.js 18+ includes native fetch support. For older versions, consider upgrading or using a polyfill like node-fetch.
3

Deno

Deno has native fetch support:
import { callApi } from "npm:@zayne-labs/callapi";

const { data } = await callApi("/api/users");
4

Bun

Bun has native fetch support:
bun add @zayne-labs/callapi
import { callApi } from "@zayne-labs/callapi";

const { data } = await callApi("/api/users");
5

Edge Runtimes

CallApi works in all edge runtimes:
  • Cloudflare Workers
  • Vercel Edge Functions
  • Deno Deploy
  • Netlify Edge Functions
  • And any other environment with native fetch

Imports

CallApi provides multiple entry points for tree-shaking optimization:

Main Package

The primary exports for making requests:
import {
  callApi,
  createFetchClient,
  createFetchClientWithContext,
} from "@zayne-labs/callapi";

Utils

Helper functions for defining schemas, plugins, and configs:
import {
  defineSchema,
  defineSchemaRoutes,
  defineMainSchema,
  defineSchemaConfig,
  definePlugin,
  defineBaseConfig,
  defineInstanceConfig,
  HTTPError,
  ValidationError,
} from "@zayne-labs/callapi/utils";

Constants

Useful constants for configuration:
import {
  HTTP_METHODS,
  STATUS_CODES,
  RETRY_STATUS_CODES,
} from "@zayne-labs/callapi/constants";
Using specific imports instead of wildcard imports helps with tree-shaking and reduces your bundle size.

TypeScript Support

CallApi is written in TypeScript and includes full type definitions out of the box. No need to install @types packages.
import { callApi, type CallApiResult } from "@zayne-labs/callapi";

interface User {
  id: number;
  name: string;
  email: string;
}

const result: CallApiResult<User> = await callApi<User>("/api/users/1");

if (result.data) {
  // data is typed as User
  console.log(result.data.name);
}

TypeScript Version

CallApi requires TypeScript 5.0 or higher for optimal type inference. Earlier versions may work but are not officially supported.
{
  "devDependencies": {
    "typescript": "^5.0.0"
  }
}

Verification

Verify your installation:
1

Check Installation

Create a test file to verify CallApi is installed correctly:
test.js
import { callApi } from "@zayne-labs/callapi";

const { data, error } = await callApi("https://jsonplaceholder.typicode.com/users/1");

if (error) {
  console.error("Error:", error.message);
} else {
  console.log("Success! User:", data);
}
2

Run the Test

node test.js
You should see the user data printed to the console.
If you’re using CommonJS (require), CallApi is ESM-only. You’ll need to use dynamic imports or migrate to ESM.

Framework Integration

CallApi works seamlessly with all modern JavaScript frameworks:
import { createFetchClient } from "@zayne-labs/callapi";
import { useState, useEffect } from "react";

// Create client outside component for reuse
const api = createFetchClient({
  baseURL: "https://api.example.com",
});

function UserList() {
  const [users, setUsers] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const fetchUsers = async () => {
      const { data, error } = await api("/users");
      if (data) setUsers(data);
      setLoading(false);
    };

    fetchUsers();
  }, []);

  if (loading) return <div>Loading...</div>;
  return <ul>{users.map(user => <li key={user.id}>{user.name}</li>)}</ul>;
}

Build Tools

CallApi works with all modern build tools:
No configuration needed! CallApi works out of the box with Vite:
vite.config.js
import { defineConfig } from "vite";

export default defineConfig({
  // No special config needed for CallApi
});

Optional: Validation Libraries

To use schema validation, install one of these libraries:
npm
npm install zod
import { z } from "zod";
import { createFetchClient } from "@zayne-labs/callapi";
import { defineSchema } from "@zayne-labs/callapi/utils";

const userSchema = z.object({
  id: z.number(),
  name: z.string(),
});

const api = createFetchClient({
  schema: defineSchema({
    "/users/:id": { data: userSchema },
  }),
});
CallApi supports any validation library that implements the Standard Schema specification.

Troubleshooting

If you see Cannot find module '@zayne-labs/callapi', make sure:
  1. You’ve installed the package: npm install @zayne-labs/callapi
  2. Your node_modules folder exists
  3. You’re using the correct import path
Try reinstalling:
rm -rf node_modules package-lock.json
npm install
If you’re seeing TypeScript errors:
  1. Ensure you’re using TypeScript 5.0+
  2. Check your tsconfig.json has "moduleResolution": "bundler" or "node16"
  3. Make sure "esModuleInterop": true is set
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "target": "ES2022"
  }
}
CallApi is ESM-only. If you need to use it with CommonJS:
  1. Use dynamic imports:
const { callApi } = await import("@zayne-labs/callapi");
  1. Or migrate your project to ESM by adding "type": "module" to your package.json:
package.json
{
  "type": "module"
}
If you see fetch is not defined, you’re using Node.js version < 18.Solution:
  1. Upgrade to Node.js 18+ (recommended)
  2. Or use a polyfill like node-fetch:
import fetch from "node-fetch";
globalThis.fetch = fetch;

import { callApi } from "@zayne-labs/callapi";

Next Steps

Quick Start

Make your first request in 5 minutes

API Reference

Explore all configuration options

Core Features

Discover CallApi’s powerful features

Advanced

Learn about type safety features

Build docs developers (and LLMs) love