6 releases
Uses new Rust 2024
0.1.8 | Apr 17, 2025 |
---|---|
0.1.7 | Apr 12, 2025 |
0.1.6 | Mar 31, 2025 |
#317 in HTTP server
61KB
1K
SLoC
🚀 Dynamic Mock API
A powerful, flexible mock server to simulate REST & GraphQL APIs with customizable behavior—ideal for frontend development, integration testing, and rapid prototyping.
🌟 What Is It?
Dynamic Mock API lets you:
- Define endpoints via a web interface
- Return custom JSON responses
- Simulate authentication, rate limits, delays, and more
- Mock GraphQL queries and mutations
- Use dynamic variables in responses
Whether you're building web apps, mobile clients, or testing backend integrations—this tool helps you simulate real-world APIs effortlessly.
✨ Key Features
Feature | Description |
---|---|
🧩 Easy Endpoint Setup | Register REST/GraphQL endpoints using a friendly UI |
📄 JSON Mock Responses | Return static or dynamic JSON responses |
🔒 Authentication | Support for Basic Auth and Bearer Token validation |
⏱️ Rate Limiting | Limit number of requests per time window |
⏳ Configurable Delays | Simulate network latency in milliseconds |
🔁 Custom HTTP Status Codes | Return success, redirects, client or server error responses |
📊 Request Logging | Logs every request with metadata |
🧪 GraphQL Support | Define mock responses for queries and mutations |
🧠 Dynamic Response Variables | Insert request values into your JSON response (e.g., path/query/header) |
🔌 gRPC Simulation | Mock gRPC service calls using HTTP-based endpoints |
⚙️ Installation & Setup
🔧 Prerequisites
- Rust: Install Rust
- Node.js + npm: Install Node.js (LTS version recommended)
🏗️ Build & Run
Linux / macOS
cd mockiapi
chmod +x init.sh
./init.sh
Windows
double-click init.bat
Access the App
Open your browser: http://localhost:3001
📚 Usage Examples
1️⃣ Register a Simple GET Endpoint
Create a file hello.json
:
{ "message": "Hello, world!" }
Register in UI:
Path | Method | Response |
---|---|---|
/api/hello |
GET | hello.json |
2️⃣ Dynamic Response Variables
{
"message": "Hello, {{name}}!",
"user_id": "{{id}}",
"requested_item": "{{item}}",
"timestamp": "{{timestamp}}"
}
Register in UI:
Path | Dynamic Vars |
---|---|
/api/user/{id}/item/{item}?name={name} |
✅ |
Request:
GET /api/user/123/item/laptop?name=John
Response:
{
"message": "Hello, John!",
"user_id": "123",
"requested_item": "laptop",
"timestamp": "2025-03-31T12:00:00Z"
}
3️⃣ GraphQL Mock Example
Check graphql.json
in uploads folder
Request:
{ "query": "query getUser { id name email }" }
Or:
{ "query": "mutation createUser { success user { id name email } }" }
Response (automatically matched):
{
"data": {
"id": "123",
"name": "Alice",
"email": "alice@example.com"
}
}
1️⃣ Simulate a gRPC Call
You can simulate gRPC service methods via HTTP by registering an endpoint with the following structure:
Example: POST /grpc
→ will be the default endpoint
Fill the form with the information required and register the following json:
{
"id": "b123",
"title": "The Rust Programming Language",
"author": "Steve Klabnik"
}
Then do a POST to /grpc with the following request body:
{
"service": "com.example.BookService",
"rpc": "GetBook",
"request": { "id": "b123" }
}
The response will be the contents of the json registered
🧠 Why Use This?
Benefit | Description |
---|---|
✅ Developer-Friendly | Configure endpoints easily through a UI—no need to edit JSON or YAML files |
🚫 No Java Required | Built in Rust, so there’s no need for a Java runtime or heavy frameworks |
⚙️ Feature-Rich | Includes auth, delays, rate limiting, and dynamic vars out of the box |
🔁 Instant Mock Updates | Change responses on the fly without restarting or redeploying |
🌍 Language-Agnostic | Works with any tech stack that supports HTTP requests |
🧪 GraphQL Support | Simulate GraphQL queries and mutations with minimal setup |
🔐 Authentication | Easily test Basic or Token-protected endpoints |
Dependencies
~15–26MB
~387K SLoC