Sign inSign up

mortenahohub/mockforge

By mortenahohub

•Updated 4 months ago

Dynamic mock API generator

Image
Languages & frameworks
API management
0

186

mortenahohub/mockforge repository overview

⁠MockForge

Dynamic mock API generator — define REST services from JSON schemas, generate fake data, and manage records through a Blazor admin UI. One container includes Admin + API + Swagger.

Built with ASP.NET Core 10, PostgreSQL (JSONB), and MudBlazor.


⁠What's inside this image

ComponentPath
Admin panelhttp://localhost:5014/
REST APIhttp://localhost:5014/api/...
Swagger UIhttp://localhost:5014/swagger
Health checkhttp://localhost:5014/health

This image does not include PostgreSQL. You need a separate Postgres instance.


⁠Quick start

⁠1. Pull the image
docker pull mortenahohub/mockforge:latest
⁠2. Start PostgreSQL
docker run -d --name mockforge-postgres \
  -e POSTGRES_DB=mockforge \
  -e POSTGRES_USER=mori \
  -e POSTGRES_PASSWORD=1662 \
  -p 5433:5432 \
  postgres:16-alpine
⁠3. Run MockForge
docker run -d --name mockforge \
  -p 5014:8080 \
  -e ConnectionStrings__Default="Host=host.docker.internal;Port=5433;Database=mockforge;Username=mori;Password=1662" \
  mortenahohub/mockforge:latest

Linux: replace host.docker.internal with your Postgres host IP or use a shared Docker network.

⁠4. Open in browser

Clone the repository and run:

docker compose up -d

This starts Postgres + MockForge together with the correct connection string.


⁠Environment variables

VariableDefaultDescription
ConnectionStrings__Default—Required. PostgreSQL connection string
Backend__ModeDirectIn-process backend (single-container mode)
Backend__ExposeApitrueExpose REST API on the same port as Admin
Backend__EnableSwaggertrueEnable Swagger UI at /swagger
ASPNETCORE_URLShttp://+:8080Listen address inside the container

⁠Features

⁠Schema & admin
  • Visual schema builder — fields, nested objects, arrays, min/max constraints
  • Nested record forms — edit Object/Array data in the admin UI
  • Import / export — share service definitions as JSON (buttons in Services list)
  • Server-side search & paging — Data grid queries the API (no in-memory filter)
  • Per-service OpenAPI — GET /api/services/{id}/openapi.json
⁠Dynamic API
  • Dynamic CRUD — each service gets its own route (e.g. /api/users)
  • PATCH — partial updates on item routes
  • Flexible record routing — business key or internal Guid:
    • /api/users/1277
    • /api/users/96ff0065-2ac7-4186-aa67-f11cf7b4d2aa
  • Auto-detected primary keys — id, userid, *id suffix, or explicit primaryKeyField
  • List search & pagination — ?search=john&page=1&pageSize=10
  • Nested search — finds values inside nested objects (e.g. address.city)
  • Sort — optional sortBy / sortDir query params
  • Reference fields — FK-style links between services
  • Custom response envelopes — { responsecode, responsemessage, data } with configurable keys
  • Custom pagination metadata — configurable page, totalCount, hasNextPage, etc.
  • Envelope request bodies — PUT/POST accepts { "data": { ... } } or flat JSON
  • Fake data generator — Bogus-powered seeding from schema
  • RFC 7807 validation errors
⁠Mock behavior (professional mocks)
  • Latency simulation — random delay (min/max ms) per service
  • Random errors — configurable error rate and status code (4xx/5xx)
  • Conditional responses — return a custom status + JSON body when a rule matches (see below)

⁠Conditional responses (simple guide)

Return a fake answer instead of normal CRUD when a condition matches — useful for testing 404, 403, etc. in your frontend.

Two ways to match:

Match typeExampleWhen it runs
URL keyUrlKeyEquals = 0GET /api/users/0 → your custom 404
Field valueField = userid, Equals = 999Body (POST/PUT) or loaded record (GET item)

Applies to: GET /{id}, POST, PUT, PATCH — not list (GET collection) or DELETE.

Example rule: if URL ends with 0, return 404:

{
  "urlKeyEquals": "0",
  "statusCode": 404,
  "body": { "message": "User not found" }
}

Configure rules in Edit service → Schema Builder → Conditional responses.


⁠Example API usage

# Health
curl http://localhost:5014/health

# Create a service
curl -X POST http://localhost:5014/api/services \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Users",
    "route": "/api/users",
    "schemaDefinition": {
      "primaryKeyField": "userid",
      "fields": [
        { "name": "userid", "type": "Int", "required": true, "unique": true, "searchable": true },
        { "name": "fullname", "type": "String", "searchable": true },
        { "name": "email", "type": "Email", "required": true, "unique": true }
      ],
      "response": { "style": "Envelope" },
      "query": { "enableSearch": true, "enablePagination": true }
    }
  }'

# Export / import service definition
curl http://localhost:5014/api/services/{id}/export
curl -X POST http://localhost:5014/api/services/import -H "Content-Type: application/json" -d @service.json

# Per-service OpenAPI
curl http://localhost:5014/api/services/{id}/openapi.json

# Seed fake data
curl -X POST "http://localhost:5014/api/services/{id}/seed?count=10"

# List with search + pagination (nested fields searched automatically)
curl "http://localhost:5014/api/users?search=john&page=1&pageSize=10"

# Get / update / patch / delete one record
curl http://localhost:5014/api/users/1277
curl -X PUT http://localhost:5014/api/users/1277 -H "Content-Type: application/json" -d '{"userid":1277,"fullname":"Jane"}'
curl -X PATCH http://localhost:5014/api/users/1277 -H "Content-Type: application/json" -d '{"fullname":"Jane Doe"}'
curl -X DELETE http://localhost:5014/api/users/1277

⁠Ports

Map container port 8080 to any host port:

docker run -p 5014:8080 ...   # Admin + API on 5014
docker run -p 8080:8080 ...   # Admin + API on 8080

There is no separate API port — frontend and backend share one port.


⁠Tags

TagDescription
latestCurrent stable build

⁠Source

MockForge — Dynamic Mock API Studio
.NET 10 · PostgreSQL · Blazor Server · MudBlazor

Tag summary

Content type

Image

Digest

sha256:da2435e50…

Size

98.9 MB

Last updated

4 months ago

docker pull mortenahohub/mockforge