FetchXY
FetchXY is a lightweight and flexible HTTP client for TypeScript/JavaScript applications, providing a simple interface for making HTTP requests with built-in timeout handling, retries, and error management.
Features
- 🚀 Promise-based HTTP client
- ⚡ Automatic timeout handling
- 🔄 Request retries with configurable conditions
- 📦 TypeScript support
- 🛠 Configurable defaults
- 🎯 Simple and intuitive API
Installation
npm install fetch-xy
Usage
Basic Example
import FetchXY from 'fetch-xy';
const client = new FetchXY();
const response = await client.get('https://api.github.com/users/octocat');
console.log(response);
const responseWithRetries = await client.get('https://api.github.com/users/octocat', {
retries: 3,
timeout: 5000,
retryDelay: 1000,
retryIf: [408, 500]
});
Advanced Configuration
const client = new FetchXY({
timeout: 5000,
retries: 3,
retryDelay: 2000,
retryIf: [408, 500, 502, 503, 504],
headers: {
'Authorization': 'Bearer your-token'
}
});
Retry Configuration Examples
const client = new FetchXY({
retries: 2,
retryIf: [408, 500]
});
const response = await client.get('https://api.example.com/data', {
retries: 3,
retryDelay: 1000,
retryIf: [503, 504]
});
const response = await client.post('https://api.example.com/data', {
timeout: 3000,
retries: 2,
data: {
name: 'John Doe'
}
});
Available Methods
get(url, config)
post(url, config)
put(url, config)
delete(url, config)
patch(url, config)
Development
Prerequisites
- Node.js (v20 or higher)
- npm or yarn
Setting Up the Development Environment
git clone https://github.com/cardoso222/FetchXY.git
cd FetchXY
npm install
npm run build
Running Tests
npm test
Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add some amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
Contribution Guidelines
- Write clear and descriptive commit messages
- Add tests for new features
- Update documentation as needed
- Follow the existing code style
- Make sure all tests pass before submitting a PR
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.