1.0.14 • Published 5 months ago

foxios v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

npm version install size Known Vulnerabilities

Features

  • 🚫 Zero Dependency: No extra libraries required.
  • 🔥 100% TypeScript: Fully typed for robust development.
  • 📦 Small Bundle Size: Approximately 600 bytes gzipped.
  • 🌐 Relative & Absolute URL Support: Automatically resolves relative URLs based on baseURL or the current browser origin.
  • ⏱️ Timeout & Cancellation: Built-in support for request timeouts and cancellation using AbortController.
  • 🛠️ Nested Query Parameters & interceptors: Easily pass deep nested objects and arrays as query parameters and inject using interceptors.
  • Modern Fetch API: Leverages the native Fetch API for fast and efficient HTTP requests.
  • Enhanced Error Handling: Rich error objects (FoxiosError) with detailed status, response, and additional flags for timeouts and cancellations.

Installation

npm install foxios

or

yarn add foxios

Usage

Import Foxios

import foxios from 'foxios';

GET Request

const response = await foxios.get('/posts', {
  baseURL: 'https://jsonplaceholder.typicode.com',
  queryParams: { _limit: 5 },
  headers: {
    'Content-Type': 'application/json',
  },
  withCredentials: true,
});
console.log(response.data);

POST Request

const response = await foxios.post(
  '/posts',
  {
    title: 'Hello World',
    body: 'This is a test post.',
    userId: 1,
  },
  {
    baseURL: 'https://jsonplaceholder.typicode.com',
    headers: {
      'Content-Type': 'application/json',
    }, // optional: used to set http header as json
    withCredentials: true, // optional: used to pass cookies
  }
);
console.log(response.data);

PUT Request

const response = await foxios.put(
  '/posts/1',
  {
    title: 'Updated Title',
    body: 'Updated Content.',
  },
  {
    baseURL: 'https://jsonplaceholder.typicode.com',
  }
);
console.log(response.data);

DELETE Request

const response = await foxios.delete('/posts/1', {
  baseURL: 'https://jsonplaceholder.typicode.com',
});
console.log(response.data);

Error Handling

try {
  const response = await foxios.get('/invalid-url', {
    baseURL: 'https://jsonplaceholder.typicode.com',
  });
} catch (error) {
  console.error('Request failed:', error);
}

Contribution Guidelines

How to Contribute

  • Fork the repository.
  • Create a feature branch.
  • Commit your changes with clear messages.
  • Open a pull request.

Code Style

  • Follow TypeScript best practices.
  • Use meaningful variable and function names.
  • Maintain clean and readable code.

Reporting Issues

  • Open an issue with clear reproduction steps.
  • Provide expected and actual behavior.

Foxios is open-source and contributions are welcome! 🚀

1.0.14

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.3

5 months ago