Skip to main content

A mock API that returns new fake users on every call

For a mock API for testing that returns fresh fake users, create a Buggregator mock rule with template: true and put fake helpers in its body. Each call to /mock/... then gets new names and emails; set a seed when you need the same data every time.

Steps

1. Write the body with fake helpers

Pass every string through | json. It adds the quotes and escapes them, so the body stays valid JSON.

text
{"name": {{ fake "name" | json }}, "email": {{ fake "email" | json }}}

2. Create a template rule

Send the rule to the REST API. template: true makes the body and every header value a template. {{ path "id" }} copies the id from the URL. This example sets seed: 42, which gives the same fake data on every request. Leave seed out (the default is 0) to get new data on every request.

bash
curl -X POST http://127.0.0.1:8000/api/mocks \
  -H 'Content-Type: application/json' \
  -d '{"method": "GET", "path": "/users/{id}", "template": true, "seed": 42,
       "headers": {"Content-Type": "application/json"},
       "body": "{\"id\": {{ path \"id\" }}, \"name\": {{ fake \"name\" | json }}, \"email\": {{ fake \"email\" | json }}}"}'

3. Call the mock

Point your app or test at http://127.0.0.1:8000/mock. With seed: 42, this is the answer every time.

bash
curl http://127.0.0.1:8000/mock/users/42
# {"id": 42, "name": "Jessica Hills", "email": "jonathon.marquardt@wilkinson.biz"}

4. Find more generators

Numbers, UUIDs, cities, prices and many more are available. The full list with each generator's parameters comes from one endpoint.

text
GET /api/mocks/helpers

Why it works

A template rule builds the body for each request instead of sending a fixed one. With seed: 0, the fake values change on every request. With any other seed, the fake data repeats, which suits tests that compare responses.

Checked on with Buggregator v2.8.0

Setup in 60 seconds

No registration. No account. Start it and point your app at it.

1

Start Buggregator

One file, installed with one command. The web UI opens on port 8000. Prefer containers? Use the Docker tab.

$ curl -fsSL https://raw.githubusercontent.com/buggregator/server/master/scripts/install.sh | sh
$ HTTP_ADDR=127.0.0.1:8000 \
  SMTP_ADDR=127.0.0.1:1025 \
  VAR_DUMPER_ADDR=127.0.0.1:9912 \
  MONOLOG_ADDR=127.0.0.1:9913 \
  PROXY_ADDR=127.0.0.1:8080 \
  ~/.local/bin/buggregator

The script picks the file for your CPU: Intel/AMD or ARM.

One file for Linux, macOS and Windows, about 40 MB. Nothing else to install.

This run line keeps it on this computer. Without the *_ADDR settings it listens on all network interfaces →

Rather not run a script? Download the file yourself →

Runs on Windows, macOS and Linux, on Intel/AMD and ARM.

Prefer not to do it yourself? Your AI agent can set Buggregator up for you →