# How to overwrite request in SLIM 4

**URL:** <https://discourse.slimframework.com/t/how-to-overwrite-request-in-slim-4/3621>\
**Category:** Questions\
**Created:** [November 6, 2019, 2:32pm UTC](https://discourse.slimframework.com/t/how-to-overwrite-request-in-slim-4/3621 "2019-11-06T14:32:02Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![andrei.neneve](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@andrei.neneve](https://discourse.slimframework.com/u/andrei.neneve)\
**Post date:** [November 6, 2019, 5:47pm UTC](https://discourse.slimframework.com/t/how-to-overwrite-request-in-slim-4/3621/5 "2019-11-06T17:47:06Z")

</div>

We are trying to create a **new custom function in REQUEST.**  
We only have a slim 3 code for response:  
Response Class:  
\<?php  
class ResponseHandler extends \Slim\Psr7\Response  
{

```
    private $data;

    public function getData()
    {
        return $this->data;
    }
    public function withData($data)
    {
        $clone = clone $this;
        $clone->data = $data;
        return $clone;
    }
}

In container:
$container->set('response', function ($container) {
    $headers = new \Slim\Http\Headers(['Content-Type' => 'application/json; charset=UTF-8']);
    $response = new ResponseHandler(200, $headers);

    return $response->withProtocolVersion($container->get('settings')['httpVersion']);
});

```

And we can use it normally:  
return $response-\>withData([  
‘id’ =\> $this-\>get\_id($mdl),  
‘message’ =\> ‘Salvo com sucesso’  
]);

---

_[View the full topic](https://discourse.slimframework.com/t/how-to-overwrite-request-in-slim-4/3621)._
