Quick Summary
- What: API Spec Sniffer automatically discovers and documents API endpoints by analyzing network traffic, generating OpenAPI specs from observed patterns.
The Problem: When 'Self-Documenting' Means 'Good Luck, Sucker'
Let's talk about the great lie of our industry: "self-documenting code." This magical phrase gets tossed around in planning meetings by managers who haven't written a line of code since Y2K was a concern. "The API is self-documenting," they say with the confidence of someone who's never had to figure out why GET /users returns an array on Tuesday but a single object on Wednesday if it's raining.
The reality is that "self-documenting" has become corporate-speak for "we shipped the feature, documentation is future us's problem." Future you, of course, is currently past you screaming at a monitor because the status field sometimes contains "active," sometimes "ACTIVE," and sometimes the number 1—because consistency is for people with free time.
Consider the legacy system that's been running since the Obama administration. The original developers have moved on to blockchain or farming or whatever developers do when they achieve enlightenment. What remains is an API that responds to endpoints discovered through tribal knowledge, server logs that look like they're written in Elvish, and response formats that change based on the phase of the moon. You're not a developer at this point—you're an API archaeologist, carefully brushing away layers of technical debt to uncover what might have been intended.
The Solution: Making Guessing a Science
Enter API Spec Sniffer, the tool that does what your product manager promised the API would do: actually document itself. Instead of relying on the honor system ("surely they'll document this endpoint eventually"), it takes a more pragmatic approach: observing what actually happens and building documentation from reality.
I built API Spec Sniffer after my third consecutive week of playing "API roulette" with a third-party service that charged us $10,000 a month but couldn't be bothered to tell us which fields were required. The tool works on a simple principle: instead of reading documentation that doesn't exist, read the traffic that does exist. It's like being a detective, except instead of solving crimes, you're solving why PUT /resource returns 200 sometimes and 204 other times.
The beauty of this approach is its honesty. Traditional documentation tells you what the API should do. API Spec Sniffer tells you what the API actually does. In the world of legacy code and rushed features, these are often two very different things. The tool doesn't judge the inconsistency—it just documents it, flags it, and gives you a confidence score so you know exactly how much to trust each endpoint.
How to Use It: Because Reading is Faster Than Guessing
Getting started with API Spec Sniffer is easier than explaining to your manager why the integration is delayed because the API documentation was a single sentence that said "it's RESTful." First, install it:
npm install -g api-spec-sniffer
# or
pip install api-spec-sniffer
Then point it at your traffic source. The tool can analyze live network traffic, parse server logs, or even examine HAR files from your browser. Here's a basic example from the main source code:
from api_spec_sniffer import APISniffer
# Analyze live traffic on port 8080
sniffer = APISniffer(port=8080)
sniffer.start_capture()
# Or parse existing logs
spec = sniffer.analyze_logs('server.log')
# Generate OpenAPI spec
openapi_spec = spec.generate_openapi()
print(f"Discovered {len(spec.endpoints)} endpoints")
print(f"Confidence score: {spec.confidence:.2%}")
Check out the full source code on GitHub for more advanced examples, like filtering specific endpoints or handling authentication patterns. The tool creates a living document that updates as it observes more traffic, which is more than can be said for that Confluence page last updated in 2018.
Key Features: Because Features Should Actually Be Useful
- Auto-discovers API endpoints by analyzing network traffic or server logs: It finds endpoints you didn't know existed, like that
/admin/delete-everythingendpoint the intern added in 2017. - Generates basic OpenAPI/Swagger spec from observed patterns: Creates documentation in a standard format, because proprietary documentation systems are where good ideas go to die.
- Flags inconsistent response formats and undocumented parameters: Highlights when the same endpoint returns different shapes, because nothing says "professional" like inconsistent JSON.
- Creates 'probable documentation' with confidence scores for each guess: Tells you how sure it is about each discovery, because 95% confidence is better than the 0% you get from an empty README.
Conclusion: From Archaeology to Actual Productivity
API Spec Sniffer won't fix the cultural problem of prioritizing shipping over documentation. It won't make your product manager suddenly care about developer experience. But it will save you from the endless cycle of trial-and-error that comes with undocumented APIs. It turns API exploration from an artisanal craft ("I feel like it wants a trailing slash today") into a systematic process.
The tool is open source, free, and available right now at https://github.com/BoopyCode/api-spec-sniffer-1767075481. Try it on that legacy system that's been giving you nightmares. Run it against that third-party API that charges you per request but can't provide a spec. Use it to document what should have been documented years ago.
Because in a perfect world, all APIs would be properly documented. But in our world, sometimes you need a tool that's comfortable with imperfection. API Spec Sniffer doesn't promise perfect documentation—just documentation that's better than nothing. And in the land of the undocumented, the one-page spec is king.
💬 Discussion
Add a Comment