Data Generators

Data Generators with Mockadillo is straightforward. Injecting a custom text in your response body and voila, you will have generic data on every request.

Mockadillo is empowered by our data generator engine which enables you to create random data for every response.

Data Generators

With our data generator syntax defined in the response body, you get a randomized response every time.

Available generator values are:

  • $$fullName$$ - Generates a full name
  • $$name$$ - Alias, generates a full name
  • $$firstName$$ - Generates a first name
  • $$lastName$$ - Generates a last name
  • $$companyName$$ - Generates a company name
  • $$company$$ - Generates a company name
  • $$product$$ - Generates a product name
  • $$country$$ - Generates a country name
  • $$gender$$ - Generates a random gender
  • $$month$$ - Generates a random month string
  • $$email$$ - Generates a random email
  • $$description$$ - Generates a random description string
  • $$password$$ - Generates a random password
  • $$state$$ - Generates a random US state
  • $$address$$ - Generates a random address
  • $$rand(min, max)$$ - Generates a random integer value between min and max
  • $$now(format)$$ - Returns the current date/time in the provided golang format
  • $$dateAdd(years_offset, months_offset, days_offset, format)$$ - Returns the relative date/time in the provided golang format

You use these values in the following way:

{
  "User":  {
    "name":  "$$name$$",
    "company":  "$$company$$",
    "contactDetails": {
      "number": "$$phoneNumber$$",
      "address": "$$address$$",
      "country": "$$country$$"
    }
  }
}

The values are interpreted at their location so it is up to you to validate the JSON surrounding them. For example

{
  "User":  {
    "name":  $$name$$
  }
}

This will generate invalid JSON since the $$name$$ function is not enclosed in quotes.

{
  "User":  {
    "ShoeSize":  "$$rand(5, 15)$$"
  }
}

In case of an invalid function invocation like $$dateAdd(0, 1, 1)$$ function will output an error to the invocation position when returning a response.

{
  "User":  {
    "DateAdded":  "Invalid number of arguments passed to function, expected 4"
  }
}