Responses behaviour

As developers we appreciate the versatility of the tools we use in our regular developments and how they improve our productivity. That's why Mockly seeks to improve your development speed helping you where others can't.

One thing we love in our developments it's the ability to change the services responses as we desire to check how the application behave in different scenarios.

Configuring responses

To modify services default responses you need to create, at least, one file called {name}.responses.json. This file should contain a responses key with the responses configuration you want to change. This key contains a configuration array where every item should follow the next schema:

Configuration example

Now you've learnt how you can configure the responses let see an example:

You can use a provided JSON schema to validate this file

all.responses.config.json
{
    "$shema": "node_modules/@mockly/server/tools/schemas/responses-config.json",
    "responses": [
        {
            "path": "/me",
            "method": "GET",
            "status": 401,
            "body": "Unauthorized"
        }, 
        {
            "path": "/artists",
            "method": "POST",
            "status": 500,
            "body": {
                "message": "Internal server error"
            }
        }
    ]
}

With this configuration the next GET request to /me will return a 401 status code and the POST requests to /artists will return a 500 status code.

Last updated