mockjsonapi
A mock server for a generic JSON API built with Delphi and delphimvcframework
- Active · last change 2-26-2026
- ★ 41 on GitHub
README
MockJSONAPI Server
MockJSONAPI is a zero-configuration mock REST server built with Delphi and DelphiMVCFramework. It exposes a full CRUD interface backed by a single JSON file — no database, no setup.
Use it to prototype REST clients (mobile apps, SPAs, desktop thin clients) without waiting for the real backend to be ready.
Grab the latest binary release here or compile from source.
Quick Start
- Place
data.jsonin the same folder asmockjsonapi.exe - Optionally create a
.envfile to set the port (default8080):port = 8080 - Run
mockjsonapi.exe - The server is ready at
http://localhost:8080
Data File
The data.json file contains all the resources served by the API. Each top-level key is a resource name, its value is an array of entities:
{
"customers": [
{
"_oid": "1",
"name": "Daniele Teti",
"email": "daniele@example.com"
},
{
"_oid": "2",
"name": "Bruce Banner",
"email": "bruce@example.com"
}
],
"products": []
}_oidis the unique identifier for each entity (Object ID).- When you
POSTa new entity, the server auto-generates an_oid(UUID) if not provided. - If you request a resource that doesn't exist in
data.json, an empty array is returned (not an error). - If you
POSTto a resource that doesn't exist, it is created automatically.
API Endpoints
All endpoints use the base path /api.
| Method | URL | Description | Status |
|---|---|---|---|
GET |
/api/{resource} |
Get all entities in a resource | 200 |
GET |
/api/{resource}/{oid} |
Get a single entity by _oid |
200 / 404 |
POST |
/api/{resource} |
Create a new entity | 201 |
PUT |
/api/{resource}/{oid} |
Update an existing entity | 200 |
DELETE |
/api/{resource}/{oid} |
Delete an entity | 200 |
DELETE |
/api/{resource} |
Delete an entire resource | 200 |
Response Format
All responses are JSON wrapped in a data property:
GET collection — returns the array of entities:
{"data": [{"_oid": "1", "name": "Daniele Teti"}, {"_oid": "2", "name": "Bruce Banner"}]}GET single entity — returns the entity object:
{"data": {"_oid": "1", "name": "Daniele Teti"}}POST — returns status and the reference URL to the created entity:
{"data": {"status": "ok", "xref": "/api/customers/A1B2C3D4-..."}}The Location and X-REF headers also contain the URL of the new entity.
PUT / DELETE — returns status:
{"data": {"status": "ok"}}Errors (e.g. entity not found) — returns a 404:
{"message": "Not Found", "statuscode": 404}curl Examples
List all customers:
curl http://localhost:8080/api/customersGet a single customer:
curl http://localhost:8080/api/customers/1Create a customer:
curl -X POST http://localhost:8080/api/customers \
-H "Content-Type: application/json" \
-d '{"name": "Tony Stark", "email": "tony@stark.com"}'Update a customer:
curl -X PUT http://localhost:8080/api/customers/1 \
-H "Content-Type: application/json" \
-d '{"name": "Daniele Teti", "email": "daniele@new.com"}'Delete a customer:
curl -X DELETE http://localhost:8080/api/customers/1CORS
CORS is enabled by default (Access-Control-Allow-Origin: *), so the API can be called directly from any web page or SPA running on a different origin.
Built With
- Delphi — Object Pascal
- DelphiMVCFramework — Web framework for Delphi
License
Apache License 2.0 — see LICENSE for details.

