Skip to content

suissa/purecore-reqify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Native Node.js fetch implementation with axios interface

Just swap the import and use a lighter, native implementation without changing any code.

npm version downloads license bundle size


🎯 Why Reqify?

Tired of heavy HTTP libraries? Reqify is a lightweight, native Node.js fetch implementation that provides the exact same interface as axios. Just change the import and enjoy a smaller bundle size!

✨ Key Features

⚑

Native Fetch
Zero dependencies, pure Node.js

πŸ”„

Drop-in Replacement
Same axios interface

🎯

TypeScript First
Full type safety

πŸš€

Modern ES Modules
Node.js 18+ ready

πŸ“¦ Installation

# npm
npm install @purecore/reqify

# yarn
yarn add @purecore/reqify

# bun
bun add @purecore/reqify

πŸš€ Quick Start

Basic Usage

import reqify from '@purecore/reqify';

// GET request
const response = await reqify.get('https://api.example.com/users');
console.log(response.data);

// POST request
const newUser = await reqify.post('https://api.example.com/users', {
  name: 'John Doe',
  email: 'john@example.com'
});

Drop-in Replacement for Axios

// Before (with axios)
import axios from 'axios';

// After (with reqify)
import reqify from '@purecore/reqify';

// Same interface, same usage!
const response = await reqify.get('/api/users', {
  headers: {
    'Authorization': 'Bearer token'
  }
});

πŸ“š API Reference

Request Methods

// GET, DELETE, HEAD, OPTIONS
await reqify.get<T>(url, config?)
await reqify.delete<T>(url, config?)
await reqify.head<T>(url, config?)
await reqify.options<T>(url, config?)

// POST, PUT, PATCH
await reqify.post<T>(url, data?, config?)
await reqify.put<T>(url, data?, config?)
await reqify.patch<T>(url, data?, config?)

// Generic request
await reqify<T>(config)
await reqify<T>(url, config)

Request Configuration

interface ReqifyRequestConfig<D = any> {
  url: string;
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
  headers?: Record<string, string>;
  data?: D;
  params?: Record<string, string | number | boolean>;
  responseType?: 'json' | 'text' | 'stream';
}

Response Object

interface ReqifyResponse<T = any, D = any> {
  data: T;
  status: number;
  statusText: string;
  headers: Headers;
  config: ReqifyRequestConfig<D>;
  request: Response;
}

πŸ’‘ Advanced Usage

Query Parameters

const response = await reqify.get('https://api.example.com/users', {
  params: {
    page: 1,
    limit: 10,
    active: true
  }
});
// GET https://api.example.com/users?page=1&limit=10&active=true

Custom Headers

const response = await reqify.post('https://api.example.com/users', userData, {
  headers: {
    'Authorization': 'Bearer token123',
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  }
});

Different Response Types

// JSON (default)
const jsonData = await reqify.get('/api/data');

// Text response
const textData = await reqify.get('/api/text', {
  responseType: 'text'
});

// Stream response
const streamData = await reqify.get('/api/file', {
  responseType: 'stream'
});

Error Handling

try {
  const response = await reqify.get('/api/users/123');
  console.log(response.data);
} catch (error) {
  if (error.response) {
    // Server responded with error status
    console.log(error.response.status);
    console.log(error.response.data);
  } else if (error.request) {
    // Network error
    console.log('Network error');
  } else {
    // Other error
    console.log('Error:', error.message);
  }
}

πŸ”„ Migration from Axios

Step 1: Change the import

// Before
import axios from 'axios';

// After
import reqify from '@purecore/reqify';

Step 2: Change the usage (if needed)

// Before
const response = await axios.get('/api/users');

// After (same syntax works!)
const response = await reqify.get('/api/users');

Compatibility Notes

  • βœ… Same method signatures
  • βœ… Same response structure
  • βœ… Same error handling
  • βœ… Same configuration options
  • βœ… Full TypeScript support
  • ⚠️ Some advanced axios features may not be implemented yet

πŸ§ͺ Testing

npm test

πŸ”§ Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

πŸ“„ License

MIT License - see the LICENSE file for details.


Made with πŸ’œ by the PureCore team

⭐ Star us on GitHub

About

Axios native implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published