1.0.1 • Published 9 months ago

@raiyyan/callapi v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

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

npm install @raiyyan/callapi

Usage

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

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

1.0.1

9 months ago

1.0.0

9 months ago