Skip to main content

Configuration

Mockend is configured using a .mockend.json file that you commit on your repository. You can therefore edit and work collaboratively on your mock API directly from GitHub.

.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: {    "min": "2010-01-01T00:00:00Z",    "max": "2020-12-31T23:59:59Z"  }}

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.