open-index/open-npm huggingface dataset:
npm package: @raiyyan/callapi
Description: Modern TypeScript HTTP client with error-first callbacks
Author: Mohammad Raiyyan
Latest version: 1.0.1

# CallAPI

A modern TypeScript HTTP client with error-first callbacks and built-in retry mechanisms.

## Features

- 🚀 Error-first callback pattern
- 🔄 Automatic retries
- ⚡ TypeScript support
- 🎯 Request cancellation
- ⏰ Timeout handling
- 🔒 Type-safe responses

## Installation

```bash
npm install @raiyyan/callapi
```

## Usage

```typescript
import { callAPI } from '@raiyyan/callapi';

// Basic GET request
const [error, data] = await callAPI<UserData>('/api/users');

// POST request with options
const [error, response] = await callAPI<Response>('/api/users', {
  method: 'POST',
  body: { name: 'John' },
  retries: 3,
});

// Using with subscription
const [promise, unsubscribe] = callAPI.subscribe<Data>('/api/stream');
```

## API Reference

### Options

```typescript
export type APICallOptions<M extends Method, BodyType = unknown> = {
  method?: M;
  body?: M extends 'POST' | 'PUT' ? BodyType : never;
  headers?: Record<string, string>;
  retries?: number;
  retryDelay?: number;
  enableGlobalLoader?: boolean;
  onStartLoader?: (attempt?: number) => void;
  onStopLoader?: () => void;
  timeout?: number;
};
```

## License

MIT