I Built a Mock Server in Go with 24x Performance Boost
As a full-stack developer, I work with APIs every day. Frontend waiting for backend, third-party API rate limits, microservice coordination... all these scenarios need mock data.
I've tried many mock tools, but something always felt off:
- MockServer: Powerful but heavy, requires JVM
- JSON Server: Lightweight but only REST, no dynamic responses
- Postman Mock: Requires internet, paid for team collaboration
So I decided to build my own. The goal was simple:
Zero dependencies, single binary, full-featured, high-performance
Three months later, MockAPI was born.
Results at a Glance
| Metric | Value |
|---|---|
| Runtime Dependencies | 0 |
| Installation | go install one command |
| Startup Time | < 100ms |
| Route Matching | 24x faster |
| Memory Usage | 94% less |
Features:
- ✅ REST Mock (dynamic routes, path params, wildcards, conditional responses)
- ✅ GraphQL Mock
- ✅ WebSocket Mock
- ✅ gRPC-Web Mock
- ✅ JavaScript scripting engine
- ✅ Swagger/OpenAPI import
- ✅ Built-in Web UI
- ✅ Hot reload
Why Go?
I chose Go not because I only know Go (though that's partly true), but because it fits perfectly:
1. Zero Runtime Dependencies
Compile to a single binary. Users don't need Node.js, JVM, or any other runtime. Download and run.
2. Powerful Standard Library
Go's net/http is fast, encoding/json is sufficient, embed lets you embed the Web UI in the binary.
3. Cross-Platform Compilation
Compile once, run everywhere.
4. Simple Deployment
No complex dependencies, deploy without Docker.
Performance: From O(n) to O(1)
Initially, route matching was linear search. Performance degraded as routes increased.
Solution: RouteIndex
I designed a two-layer index structure:
- Exact match: Direct map lookup, O(1)
- Param routes: Grouped by prefix, reduces candidates
- Wildcard routes: Grouped by method
Results
24x faster, 94% less memory. That's the power of choosing the right data structure.
Core Features
Dynamic Routes
Support :param and * wildcards.
JavaScript Engine
Generate dynamic responses with JavaScript when static isn't enough.
Swagger/OpenAPI Import
Import existing API docs, auto-generate mock routes.
Built-in Web UI
Manage in browser: http://localhost:8088/_ui
Features: Route management, visual editor, quick templates, request logs, real-time debugging.
Quick Start
# Install
go install github.com/fynntang/MockAPI@latest
# Run
mockapi serve Project Links
- GitHub: https://github.com/fynntang/MockAPI
- Website: https://mockapi.work
If this project helps you, please Star ⭐
Final Thoughts
Building MockAPI taught me:
- Simplicity wins - Zero dependencies beats feature bloat
- Performance early - Good data structures beat late optimization
- Developer experience matters - CLI and Web UI improve usability
- Test-driven - 26 tests let me sleep well
Happy Mocking! 🦞