Skip to main content

Configuration

Mockend is configured using a .mockend.json file that you commit on your repository.

.mockend.json
{  "ModelName": {    "fieldName": {      "<type>": {} | [],      "hasMany": "Model",      "belongsTo": "Model"    }  }}

Model#

Model names are singular and start with a capital letter.

{  "User": {},  "Post": {},  "Comment": {},  "Person": {},  "City": {}}

Field#

Field names can be any valid JSON field name.

Types#

string#

Generates a random string.

{ "title": { "string": {} }

int#

Generates a random integer between min and max.

{ "likes": { "int": { "min": 0, "max": 1000000 } } }

boolean#

Generates a random boolean.

{ "isPublished": { "boolean": {} } }

dateTime#

Generates a random RFC3339 DateTime between min and max.

{  "createdAt: {    "dateTime": {      "min": "2010-01-01T00:00:00Z",      "max": "2020-12-31T23:59:59Z"    }  }}

regexp#

Generates a random string based on regular expression.

{ "name": { "regexp": "[A-Z][a-z]{5,10}" } }
[ { "name": "Mxokole" }, { "name": "Tuilo" }, ... ]

Custom values#

To have an API closer to your domain, you can provide custom string and int values which will be randomly picked.

tip

There are many libs that lets you generate common values like names, countries, ... (e.g. Faker for Python, Faker for Ruby, ...)

tip

Editing JSON files by hand can become cumbersome. If your .mockend.json gets big, you can consider having a script to generate it instead.

string#

{  "name": {    "string": [      "Thor",      "Loki"    ]  }}
[ { "name": "Loki" }, { "name": "Loki" }, { "name": "Thor" }, ... ]

int#

{  "code": {    "int": [      100,      200,      300    ]  }}
[ { "code": 200 }, { "code": 300 }, { "code": 300 }, ... ]

Relations#

You can describe relations between models.

hasMany#

{  "Post": {    "userComments": {      "hasMany": "Comment"    }  }}

userComments field will have an array of generated Comment.

belongsTo#

{  "Comment": {    "authorPost": {      "belongsTo": "Post"    }  }}

authorPost field will have a generated Post.

note

Relations are only supported with GraphQL.

Common values#

Image#

{  "avatar": { "regexp": "https://i\\.pravatar\\.cc/150?u=[0-9]{5}" },  "photo": { "regexp": "https://picsum\\.photos/seed/[0-9]{5}/1920/1080" }}

Name#

{ "firstName": { "regexp": "[A-Z][a-z]{5,10}" } }

Email#

{ "email": { "regexp": "#[a-z]{5,10}@[a-z]{5}\\.[a-z]{2,3}" } }

Hex color#

{ "color": { "regexp": "#[0-9A-F]{6}" } }