easy-api-tester
v1.1.0
Published
Simple API testing utility like callAPI(method, url, data, headers)
Downloads
9
Maintainers
Readme
🔌 easy-api-tester
A super simple utility to test backend APIs directly from your JavaScript code — like Postman, but in code.
Supports all HTTP methods: GET, POST, PUT, DELETE, etc.
🚀 Installation
npm install easy-api-tester📦 Usage
const callAPI = require("easy-api-tester");
// ✅ Example 1: GET request
callAPI("GET", "https://jsonplaceholder.typicode.com/posts/1")
.then((res) => console.log(res))
.catch((err) => console.error(err));
// ✅ Example 2: POST request with body
callAPI("POST", "https://jsonplaceholder.typicode.com/posts", {
title: "Suman's Test",
body: "Hello from easy-api-tester!",
userId: 1,
}).then((res) => console.log(res));
//example 3
import callAPI from "easy-api-tester";
const res = await callAPI("POST", "http://localhost:3000", {
name: "easy-api-tester",
version: "1.0.0",
message: "Hello World!",
});
console.log("Response from API:", res);🧠 Parameters
callAPI(method, url, (data = {}), (headers = {}));✅ Example with Custom Headers
callAPI(
"GET",
"https://api.example.com/protected",
{},
{
Authorization: "Bearer your_token_here",
}
).then(console.log);✅ Success Response:
{
"userId": 1,
"id": 1,
"title": "Sample Title",
"body": "Sample Body"
}❌ Error Response:
{
"error": true,
"status": 404,
"message": "Not Found"
}