Sign inSign up

ragilhadi/mimic

By ragilhadi

•Updated 26 days ago

Mimic is a fast, lightweight HTTP mock server. Perfect for testing, development, and API prototyping

Image
Developer tools
0

3.9K

ragilhadi/mimic repository overview

⁠🧩 Mimic - Lightweight HTTP Mock Server

GitHub

Mimic is a fast, lightweight HTTP mock server built with Rust and Axum. Perfect for testing, development, and API prototyping. Define your mock responses in simple JSON files and let Mimic handle the rest.

⁠✨ Features

  • 🚀 Blazing Fast - Built with Rust and Axum for maximum performance
  • 💾 Ultra Lightweight - Only 1.66 MiB memory usage
  • 📁 File-Based Configuration - Define mocks in simple JSON files
  • 🔄 Hot Reload - Changes to mock files are reflected immediately
  • 🐳 Docker Ready - Pre-built images available on Docker Hub
  • ✅ Well Tested - 35+ unit tests with 90% code coverage
  • 🔧 Easy to Use - Simple configuration, no complex setup

⁠📊 Performance

Mimic is incredibly efficient and lightweight:

CONTAINER ID   NAME      CPU %     MEM USAGE / LIMIT    MEM %     NET I/O           BLOCK I/O   PIDS
b056ebec5099   mimic     0.02%     1.66MiB / 6.238GiB   0.03%     17.1kB / 34.6kB   0B / 0B     17

Key Metrics:

  • Memory Usage: Only 1.66 MiB (yes, megabytes!)
  • CPU Usage: 0.02% at idle
  • Startup Time: < 1 second
  • Response Time: < 10ms for most requests

Perfect for resource-constrained environments, CI/CD pipelines, and local development.


⁠🚀 Quick Start

Pull the latest image from Docker Hub:

docker pull ragilhadi/mimic:latest

Run with your mock files:

docker run -d \
  --name mimic \
  -p 8080:8080 \
  -v $(pwd)/mocks:/app/mocks:ro \
  ragilhadi/mimic:latest

Test it:

curl http://localhost:8080/health
⁠Using Docker Compose
  1. Create a docker-compose.yml:
services:
  mimic:
    image: ragilhadi/mimic:latest
    container_name: mimic
    ports:
      - "8080:8080"
    volumes:
      - ./mocks:/app/mocks:ro
    environment:
      - PORT=8080
      - RUST_LOG=info
    restart: unless-stopped
  1. Start the service:
docker compose up -d

⁠📝 Configuration

⁠Environment Variables

Create a .env file to customize your setup:

# Port configuration (default: 8080)
PORT=8080

# Logging level: trace, debug, info, warn, error (default: info)
RUST_LOG=info

Log Levels:

  • trace - Very detailed debugging
  • debug - Detailed debugging
  • info - General information (recommended)
  • warn - Warnings only
  • error - Errors only
⁠Mock Files

Mimic reads mock definitions from JSON files in the /app/mocks directory (or ./mocks locally).

Mock File Structure:

{
  "method": "GET",
  "path": "/users",
  "status": 200,
  "response": {
    "users": [
      {
        "id": 1,
        "name": "Alice Johnson",
        "email": "[email protected]"
      }
    ]
  }
}

Fields:

  • method - HTTP method (GET, POST, PUT, DELETE, PATCH, etc.)
  • path - URL path (e.g., /users, /api/v1/products)
  • status - HTTP status code (200, 201, 404, 500, etc.)
  • response - JSON response body (can be object, array, or null)

⁠📁 Mock Examples

⁠Example 1: GET Request

File: mocks/get_users.json

{
  "method": "GET",
  "path": "/users",
  "status": 200,
  "response": {
    "users": [
      {
        "id": 1,
        "name": "Alice Johnson",
        "email": "[email protected]",
        "role": "admin"
      },
      {
        "id": 2,
        "name": "Bob Smith",
        "email": "[email protected]",
        "role": "user"
      }
    ],
    "total": 2
  }
}

Usage:

curl http://localhost:8080/users
⁠Example 2: POST Request

File: mocks/post_login.json

{
  "method": "POST",
  "path": "/login",
  "status": 200,
  "response": {
    "success": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "user": {
      "id": 1,
      "username": "admin",
      "email": "[email protected]"
    },
    "expiresIn": 3600
  }
}

Usage:

curl -X POST http://localhost:8080/login
⁠Example 3: Error Response

File: mocks/get_error.json

{
  "method": "GET",
  "path": "/error",
  "status": 500,
  "response": {
    "error": "Internal Server Error",
    "message": "Something went wrong",
    "code": "ERR_500"
  }
}

Usage:

curl http://localhost:8080/error
⁠Example 4: DELETE Request

File: mocks/delete_user.json

{
  "method": "DELETE",
  "path": "/users/123",
  "status": 204,
  "response": null
}

Usage:

curl -X DELETE http://localhost:8080/users/123

Tag summary

Content type

Image

Digest

sha256:db1252039…

Size

34 MB

Last updated

26 days ago

docker pull ragilhadi/mimic