api-flex Logo

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:

  1. Install the Library: Use npm install api-flex or yarn add api-flex to add it to your project.
  2. Import the Library: Bring it into your JavaScript file with import apiFlex from "api-flex";
  3. Configure Your API Endpoints: Set up your API endpoints and any necessary options for your requests.
  4. Make API Calls: Use the simple and intuitive API to start fetching data effortlessly!

Testimonials

"This library made my API integration a breeze!"

— Jane Doe

"Fantastic tool! It's saved me so much time."

— John Smith

"Easy to use and powerful. Highly recommend!"

— Alice Johnson

FAQ

What is api-flex?

+

How do I report issues?

+

Is there any support available?

+

What platforms is api-flex compatible with?

+

How do I handle errors in api-flex?

+

Can I customize the request headers?

+

Where can I find the documentation?

+