When debugging applications, one of the most common tasks is tracking API requests and responses.
Developers often add logs everywhere:
- Before sending a request
- After receiving a response
- While debugging errors
- While analyzing performance
This quickly becomes messy and repetitive.
So I built a small npm package called auto-api-observe that automatically observes API calls in JavaScript applications.
The Problem
When working on large applications, especially microservices or frontend apps, debugging API calls can be frustrating.
Typical workflow:
- Add console logs before API calls
- Add logs after responses
- Add error logging
- Remove everything later
Example:
console.log("Request:", url);
fetch(url)
.then(res => {
console.log("Response:", res);
return res.json();
})
.catch(err => {
console.error("Error:", err);
});
Now imagine doing this across hundreds of API calls.
This is where auto-api-observe helps.
What auto-api-observe Does
This package allows you to observe API requests and responses automatically without modifying every API call.
Features:
- Observe API requests
- Observe API responses
- Capture errors
- Works with JavaScript applications
- Simple integration
Installation
npm install auto-api-observe
Basic Usage
import { observeApi } from "auto-api-observe";
observeApi({
onRequest: (req) => {
console.log("API Request:", req);
},
onResponse: (res) => {
console.log("API Response:", res);
},
onError: (err) => {
console.error("API Error:", err);
}
});
Now every API call can be observed automatically.
Example Output
API Request: GET /users
API Response: 200 OK
API Error: Network timeout
This makes debugging and monitoring much easier.
Use Cases
This package can be useful for:
- Debugging API issues
- Logging request/response flows
- Monitoring application behaviour
- Performance analysis
- Development debugging
Why I Built This
While working on large production applications, I often needed a quick way to observe API calls without modifying every request manually.
So I built auto-api-observe as a lightweight solution to simplify this process.
npm Package
You can check it here:
https://www.npmjs.com/package/auto-api-observe
GitHub
If you find it useful, feel free to star the repository and contribute.
Feedback
I would love feedback from the developer community.
If you have ideas for improvements or new features, feel free to open an issue or pull request.
Top comments (0)