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.
β
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
- 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
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
πΉ 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
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");
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();
β
No need to manually handle headers
β
No need to handle errors manually
β
Reusable client for multiple API calls
β
Cleaner, more readable code
Install via NPM:
npm install dynamic-api-wrapper
Or using Yarn:
yarn add dynamic-api-wrapper
const DynamicAPIWrapper = require("dynamic-api-wrapper");
const api = new DynamicAPIWrapper({
baseURL: "https://api.example.com",
apiKey: process.env.API_KEY, // API Key from .env
});
async function fetchUser() {
try {
const user = await api.get("/users/12345");
console.log(user);
} catch (error) {
console.error("Error:", error.message);
}
}
fetchUser();
api.post("/users", { name: "John Doe" })
.then(response => console.log(response))
.catch(error => console.error(error));
const api = new DynamicAPIWrapper({
baseURL: "https://api.example.com",
token: process.env.OAUTH_TOKEN,
authType: "oauth",
});
- Create an API client instance with
baseURL
and authentication method. - Make API calls using
get()
,post()
,put()
, ordelete()
. - 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
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();
api.get("/data", {}, { "Custom-Header": "value" });
api.get("/search", { query: "test", limit: 10 });
try {
const response = await api.get("/users/12345");
} catch (error) {
console.error("API Error:", error.message);
}
This project is licensed under the MIT License.
Read More
Ankit β Full Stack Developer
π LinkedIn
π GitHub
π NPM Profile
Contributions are welcome!
Feel free to submit issues and pull requests on GitHub.
Happy coding! π