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.
{"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.
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.
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.
GET /api/mocks/helpersWhy 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.
Docs: docs.buggregator.dev/config/mock-templates.html#fake-data
Requires Buggregator v2.6.0+
Related tips
- Mock server
A working mock API from your OpenAPI spec
Import an OpenAPI 3 spec into Buggregator. Every operation becomes a mock rule with the spec's example or fake data, served under /mock.
- HTTP
Send a captured request again with one cURL
Every request Buggregator captures comes with a ready cURL command. Copy it, paste it in a terminal, and the same request arrives again.
- HTTP
See a webhook's payload before you write the handler
Point the webhook URL at Buggregator with http-dump in the URL. See the headers, body and files it sends, plus a cURL command to send it again.
Checked on with Buggregator v2.8.0