> For the complete documentation index, see [llms.txt](https://mockly.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mockly.gitbook.io/docs/getting-started-1/configuring-responses.md).

# 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.&#x20;

### 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:

| Name    | Type                 | Required | Description                                                                                                           |
| ------- | -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| body    | `object` \| `string` | `false`  | Response body                                                                                                         |
| cookies | `object`             | `false`  | Cookies setted by the response                                                                                        |
| delay   | `number`             | `false`  | Determines how long takes the request to be resolved. Overrides generic delay configuration.                          |
| headers | `object`             | `false`  | Headers returned in the response                                                                                      |
| path    | `string`             | `true`   | Request URI to match                                                                                                  |
| method  | `string`             | `true`   | Request HTTP method to match                                                                                          |
| status  | `string`             | `false`  | Response status code. Should be a valid [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). |

### Configuration example

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

{% hint style="info" %}
You can use a provided JSON schema to validate this file
{% endhint %}

{% code title="all.responses.config.json" %}

```javascript
{
    "$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"
            }
        }
    ]
}
```

{% endcode %}

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.
