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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mockly.gitbook.io/docs/getting-started-1/configuring-responses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
