Skip to content

Dynamic API Wrapper is a lightweight and flexible API wrapper for Node.js, designed to make API integrations easier and more efficient. It supports GET, POST, PUT, DELETE, and PATCH requests while handling authentication, retries, and error management automatically.

Notifications You must be signed in to change notification settings

imankii01/Dynamic-API-Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Dynamic API Wrapper

npm version License: MIT

A powerful, flexible, and easy-to-use API wrapper for any REST API.
Simplify API integrations in Node.js with built-in authentication, error handling, and rate limiting.


🌟 Features

βœ… Supports GET, POST, PUT, DELETE, PATCH requests
βœ… Works with any REST API
βœ… Supports API Key & OAuth authentication
βœ… Automatic retries on failures & rate limits
βœ… Environment variable support (for API keys)
βœ… Modular & Extensible
βœ… TypeScript support for better DX


πŸ“Œ When to Use

  • Connecting to external REST APIs in a Node.js project
  • Building microservices that require multiple API calls
  • Simplifying API integration for internal and external services
  • Handling authentication, retries, and error handling automatically

πŸ› οΈ How This API Wrapper Makes Your Work Easier

Before using this wrapper, you might be making raw API calls manually using axios or fetch, leading to:
❌ Repeated code for handling API requests
❌ Hardcoded authentication headers everywhere
❌ No error handling for rate limits or failed requests
❌ Difficult debugging & maintenance

βœ… How This Wrapper Helps

πŸ”Ή One-time setup β†’ Initialize the client once and reuse it
πŸ”Ή Automatic authentication β†’ No need to manually add headers
πŸ”Ή Built-in error handling β†’ Automatically retries rate-limited requests
πŸ”Ή Less code, more efficiency β†’ Clean, readable API calls
πŸ”Ή Consistent API design β†’ Same method for any REST API

πŸ“Œ Example Before vs. After Using This Wrapper

❌ Without This Wrapper (Traditional Approach)

const axios = require("axios");

async function getUser(userId) {
  try {
    const response = await axios.get(`https://api.example.com/users/${userId}`, {
      headers: { Authorization: `Bearer ${process.env.API_KEY}` }
    });
    return response.data;
  } catch (error) {
    console.error("API Error:", error.message);
  }
}

getUser("12345");

βœ… With This Wrapper

const DynamicAPIWrapper = require("dynamic-api-wrapper");

const api = new DynamicAPIWrapper({
  baseURL: "https://api.example.com",
  apiKey: process.env.API_KEY,
});

async function getUser() {
  try {
    const user = await api.get("/users/12345");
    console.log(user);
  } catch (error) {
    console.error("Error:", error.message);
  }
}

getUser();

🎯 What's Different?

βœ… No need to manually handle headers
βœ… No need to handle errors manually
βœ… Reusable client for multiple API calls
βœ… Cleaner, more readable code


πŸ“¦ Installation

Install via NPM:

npm install dynamic-api-wrapper

Or using Yarn:

yarn add dynamic-api-wrapper

πŸš€ Quick Start

1️⃣ Import & Initialize

const DynamicAPIWrapper = require("dynamic-api-wrapper");

const api = new DynamicAPIWrapper({
  baseURL: "https://api.example.com",
  apiKey: process.env.API_KEY, // API Key from .env
});

2️⃣ Make API Requests

βœ… GET Request

async function fetchUser() {
  try {
    const user = await api.get("/users/12345");
    console.log(user);
  } catch (error) {
    console.error("Error:", error.message);
  }
}
fetchUser();

βœ… POST Request

api.post("/users", { name: "John Doe" })
  .then(response => console.log(response))
  .catch(error => console.error(error));

βœ… OAuth Support

const api = new DynamicAPIWrapper({
  baseURL: "https://api.example.com",
  token: process.env.OAUTH_TOKEN,
  authType: "oauth",
});

βš™οΈ How It Works

  1. Create an API client instance with baseURL and authentication method.
  2. Make API calls using get(), post(), put(), or delete().
  3. Handles rate limits, errors, and retries automatically.

βœ… Uses Axios for requests
βœ… Supports OAuth and API Key-based authentication
βœ… Retries 429 (Rate Limit Exceeded) errors automatically


πŸ› οΈ Configuration

Using .env for API Keys

Create a .env file and store your API credentials securely:

API_KEY=your_api_key_here
API_BASE_URL=https://api.example.com

Then, use it in your code:

require("dotenv").config();

πŸ’‘ Advanced Usage

Custom Headers

api.get("/data", {}, { "Custom-Header": "value" });

Sending Query Parameters

api.get("/search", { query: "test", limit: 10 });

Handling Errors

try {
  const response = await api.get("/users/12345");
} catch (error) {
  console.error("API Error:", error.message);
}

πŸ“ License

This project is licensed under the MIT License.
Read More


πŸ‘¨β€πŸ’» Author

Ankit – Full Stack Developer
πŸ”— LinkedIn
πŸ”— GitHub
πŸ”— NPM Profile

β˜• Support My Work:
Buy Me A Coffee


πŸ’¬ Contributing

Contributions are welcome!
Feel free to submit issues and pull requests on GitHub.

Happy coding! πŸš€

About

Dynamic API Wrapper is a lightweight and flexible API wrapper for Node.js, designed to make API integrations easier and more efficient. It supports GET, POST, PUT, DELETE, and PATCH requests while handling authentication, retries, and error management automatically.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published