> For the complete documentation index, see [llms.txt](https://akhilgangula.gitbook.io/mock-json-response/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akhilgangula.gitbook.io/mock-json-response/logic.md).

# Logic

Manipulating response according the request.

Changing the response data with the power of JS! Once the request is matched and response is mapped, there is one more step before mock JSON response sends a response, that's passing data to function called logic.

```javascript
logic: function (request, { data }) {
     // logic need not have any statements
}
```

logic receives request and data fetched as arguments, since data is passed by reference change in data object is sent as a response.

Here is an example:

```javascript
logic: function ({headers}, { data }) {
     data.items.push(headers['x-purchase-item'])
}
```

Once the response is processed,

```javascript
{
   ...
   items = ['Fruits','Bread'],
   ...
}
```
