Sample data that holds together
A request body usually needs a name, an email and a price that look like the real thing, and the next request needs the same customer the first one created. These functions fill bodies without a fixtures file to keep up to date.
Start with single values. fake gives one each time it is read, and uuid() a fresh id.
### Create an order
POST https://httpbingo.org/anything/orders
{
"id": "{{uuid()}}",
"customer": "{{fake.name}}",
"email": "{{fake.email}}",
"product": "{{fake.product}}",
"price": {{fake.price}}
}
> assert status == 200
> assert body.json.price > 0
> print body.json.customer + " <" + body.json.email + ">"
Anything inside {{ }} is an expression, and a body is interpolated before it is sent, so these calls work in a URL, a header or a variable too. httpbingo.org/anything sends the body straight back under json, which is why the assertions can read what went out.
stamp run orders.stamp
→ POST https://httpbingo.org/anything/orders orders.stamp › createAnOrder
200 OK 235 ms 1 KB
✓ status == 200
✓ body.json.price > 0
│ Emily Larsen <yusuf.dubois@stampdrill.dev>
✓ 1 request, 2 assertions
There are many more of these. The ones worth knowing, grouped by what they are for:
| people | firstName, name, email, username, phone, avatar, birthDate, jobTitle |
| places | street, city, country, zip, latitude |
| money and trade | company, product, price, currency, iban, creditCard, which is a published test number |
| text and ids | word, sentence, paragraph, url, ipv4, uuid, id, number, bool |
| dates | date, pastDate, futureDate |
| whole records | fake.person, fake.address, fake.organization |
Alongside them: randomInt(min, max), randomFloat(min, max, decimals), randomString(length, alphabet), oneOf(list) and shuffle(list).
Look again at the printed line, though. The name and the email in it belong to two different people, because each fake value is read on its own. When one person has to show up twice, give the record a key.
### Register the customer
POST https://httpbingo.org/anything/customers
{
"name": "{{person("cust-42").name}}",
"email": "{{person("cust-42").email}}",
"city": "{{person("cust-42").address.city}}"
}
> assert status == 200
> assert body.json.email == person("cust-42").email
### Invoice the same customer
POST https://httpbingo.org/anything/invoices
{ "customer": "{{person("cust-42").email}}", "amount": {{fake.price}} }
> assert body.json.customer == registerTheCustomer.body.json.email
person(key) gives the same record back for the same key, in any request, in any file, against any API. Its fields belong together: the email is built from the name, the username from the name, and address is a whole address inside it, so person("cust-42").address.city is where that person lives. address(key) and organization(key) work the same way.
person(key) | id, name, firstName, lastName, email, username, phone, avatar, birthDate, jobTitle, address |
address(key) | street, city, zip, country, countryCode |
organization(key) | id, name, domain, email, industry, employees, address |
The key can be anything: a number, a name, a value from an earlier response. Keys are how two requests, or two services, end up talking about the same person without a shared fixture between them.
That is enough to fill a body. The rest is about making the same values come back later.
Every run above invents new fake values and new ids. Set a seed and it stops: the same seed gives the same sequence on every run, today and next month.
@seed = order-tests
### Create an order
POST https://httpbingo.org/anything/orders
{ "id": "{{uuid()}}", "customer": "{{person(7).name}}", "price": {{fake.price}} }
> print json(body.json)
stamp run orders.stamp
→ POST https://httpbingo.org/anything/orders orders.stamp › createAnOrder
200 OK 236 ms 1 KB
│ {"customer":"Lucas Johnson","id":"ace53bca-963f-4683-88c7-38763ab86b2a","price":527.24}
✓ 1 request
Run it again and the line is identical, id and price included. Change the seed and every value in it changes. Delete the seed and the ids and the price are new each time, while person(7) stays who it was: a key is stable on its own, and the seed decides which record the key lands on.
A load test takes this further. Each scenario run gets its own seed, <seed>-<run>, so uuid("order") is one id across the requests of a single run, a different one in the next run, and the same set of ids when the whole test runs again.
When the shape of the body is already written down as a JSON Schema, mock builds a value from it. Examples, enums, formats such as email, uuid and date-time, minimums and maximums, and even property names all steer the result, so a role with three allowed values comes back as one of the three.
### Create a user from the schema
POST https://httpbingo.org/anything/users
{{ json(mock(readJson("./schemas/user.json"), "user-1")) }}
> assert status == 200
> assert ["admin", "editor", "viewer"] contains body.json.role
> assert all(body.json.tags, tag => length(tag) > 0)
readJson(path) and readText(path) read files next to the .stamp file, so that snippet wants a schema at ./schemas/user.json; the example workspace has one under Playground to copy. The second argument to mock is a key, and it behaves like the key of a person: the same key gives the same body back.
In the app
- Open the request and its Body tab. The body keeps the
{{ }}calls as you wrote them, because a generated value is decided when the request is sent and not before. - To see one without sending anything, use Request ▸ Copy as cURL (⇧⌘C) and paste it somewhere. The command is this request with every value filled in.
- Press ⌘↩.
httpbingo.org/anythinghands the body back, so the response is what was actually sent: switch it to Tree and openjsonto find the name and the email that went out. Table is offered too when the JSON is shaped like rows. - Open Console for the
printlines, with their number on the tab. - Send it a second time. With
@seedin the file the Diff tab says Nothing Changed, the same status, headers and body as the run before. Take the seed out and the same tab lists the lines that moved.
That last step is the one worth doing. A seed is a claim about two runs, and the diff of the second against the first is where the claim is either kept or broken, in the same window, without saving anything to compare later.

Next: Scripts and assertions for reading the values back out of a response, Test plans for driving a plan from the rows of a CSV instead, and Load tests for what a seed does under load.