
api-flex
A lightweight and powerful library that simplifies API integration with automatic retries, token management, and more.
Get Started🚀 Features of Api-Flex
⚡️ Circuit Breaker Feature
Enhances API request resilience by preventing repeated attempts to call a failing service, improving application stability.
Flexible API Requests
Easily make HTTP requests with a simple interface that supports both GET and POST methods.
Automatic Retries
Configurable retry logic to automatically re-fetch data in case of network failures or errors.
Timeout Handling
Customizable request timeout settings to prevent hanging requests and enhance user experience.
Interceptor Support
Ability to add request and response interceptors for modifying requests and responses effortlessly.
Environment Detection
Compatible with both Node.js and browser environments, making it versatile for various applications.
Configurable Defaults
Easily set default configurations such as headers and timeouts to streamline API calls.
Lightweight and Fast
Designed to be lightweight and efficient, ensuring minimal performance impact on applications.
Code Examples
Vanilla JavaScript
// Simple API call using Fetch API
import apiFlex from "api-flex";
const data = await apiFlex("https://jsonplaceholder.typicode.com/posts/1");
console.log(data);
Express.js
const express = require('express');
import express from "express";
import apiFlex from "api-flex";
const app = express();
app.get("/api/post", async (req, res) => {
try {
const post = await apiFlex("https://jsonplaceholder.typicode.com/posts/1");
res.json(post);
} catch (error) {
console.error("Error fetching post:", error.message);
res.status(500).send("Failed to fetch post.");
}
});
app.listen(3000, () => {
console.log("Server running on http://localhost:3000");
});
React.js
import React from "react";
import { useEffect } from "react";
import apiFlex from "api-flex"; // imported api-flex library
const App = () => {
useEffect(() => {
apiFlex("https://jsonplaceholder.typicode.com/posts/1")
.then((data) => {
console.log(data);
})
.catch((err) => console.log(err.message));
}, []);
return (
<div>
<h1>Welcome to ApiFlex Library</h1>
</div>
);
};
export default App;
🚀 Getting Started with api-flex
Follow these simple steps to start making API calls with api-flex:
- Install the Library: Use
npm install api-flex
oryarn add api-flex
to add it to your project. - Import the Library: Bring it into your JavaScript file with
import apiFlex from "api-flex";
- Configure Your API Endpoints: Set up your API endpoints and any necessary options for your requests.
- Make API Calls: Use the simple and intuitive API to start fetching data effortlessly!
Testimonials
"This library made my API integration a breeze!"
"Fantastic tool! It's saved me so much time."
"Easy to use and powerful. Highly recommend!"