Skip to content

ehippo/http-mocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpmock

A lightweight, self-hosted HTTP mock server designed to run in Kubernetes.
It serves both the Mock Engine and the Management UI/API on a single port.


Architecture Decision: StatefulSet + SQLite

The service runs as a StatefulSet with a PersistentVolumeClaim per pod.
Mocks are stored in an SQLite database on the PVC.

Why:

  • Mocks can be added, updated, and deleted at runtime without any redeployment.
  • SQLite is a single binary dependency with zero network overhead.
  • WAL mode makes concurrent reads + writes safe.
  • Easy to back up (sqlite3 mocks.db .dump > backup.sql).
  • Scales to a single-pod "always on" mock service that teams in the cluster share.

Quick Start (Local)

Prerequisites

  • Go 1.22+
  • C-Compiler (for SQLite/CGO) or use CGO_ENABLED=0 (though CGO is recommended for performance)

Run with Make

make run
# UI & Management API → http://localhost:8080/ui
# Mock Server catch-all → http://localhost:8080/*

Run with Go

go run ./cmd/server/main.go

Build with Go

go build ./cmd/server/main.go

Management API

UI Access

Open your browser at http://localhost:8080/ui.

Create a mock via CLI

POST /api/mocks
Content-Type: application/json

{
  "name": "Get user",
  "method": "GET",
  "path": "/api/users/{id}",
  "status_code": 200,
  "resp_headers": { "Content-Type": "application/json" },
  "resp_body": "{\"id\": 42, \"name\": \"Alice\"}",
  "priority": 10
}

Path Matching

Pattern Matches
/api/users exactly /api/users
/api/users/{id} /api/users/123, /api/users/abc
/api/** anything under /api/
* (method) any HTTP method

Priority

Higher priority integers are evaluated first. Default is 0.
Use this when multiple mocks could match the same path.


Configuration (Env Vars / Flags)

Env var Flag Default Description
ADDR -addr :8080 Server listen address
DB_PATH -db /data/mocks.db SQLite database path
LOG_LEVEL -log-level info debug, info, warn, error

Project Structure

.
├── cmd/server/main.go          # Entry point, wires handlers together
├── internal/
│   ├── model/mock.go           # Domain types
│   ├── store/sqlite.go         # SQLite persistence
│   └── handler/
│       ├── handler.go          # Management API handlers
│       ├── matcher.go          # Mock matching logic
│       └── ui.go               # Embedded Management UI
├── k8s/httpmock.yaml           # Kubernetes Deployment
├── Dockerfile
└── Makefile

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors