# Slim 4 - Custom Request (extending the existing Request)

**URL:** https://discourse.slimframework.com/t/slim-4-custom-request-extending-the-existing-request/4868
**Category:** Questions
**Created:** [June 25, 2021, 9:18am UTC](https://discourse.slimframework.com/t/slim-4-custom-request-extending-the-existing-request/4868 "2021-06-25T09:18:23Z")
**Posts on this page:** 1
**Showing post:** 23

<div class="post-metadata">

### Author: ![reinier](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/reinier/32/1515_2.png) [@reinier](https://discourse.slimframework.com/u/reinier)
#### Post date: [February 23, 2023, 4:27pm UTC](https://discourse.slimframework.com/t/slim-4-custom-request-extending-the-existing-request/4868/23 "2023-02-23T16:27:04Z")

</div>

**Edit** : I think i found a post that sort of explains how to do it but i could use some help there trying to figure out my usecase: [Type hinting $request-\>getAttribute("woof") / data from middleware - #10 by reuben.helms](https://discourse.slimframework.com/t/type-hinting-request-getattribute-woof-data-from-middleware/5453/10)

This is an old topic, but I am also trying to implement a custom request. I want autocomplete in my IDE for the data that is being sent with the specific request. So I wlll have a LoginUserRequest, SaveInvoiceRequest, etc.

All examples simplified ofcourse.

I want my **controller** to look something like this:

```auto
public function __invoke(
    LoginUserRequest $request, // instead of ServerRequestInterface
    ResponseInterface $response
): ResponseInterface {

    $user = ($this->LoginUserAction)($request);

    return $response->withJson([
            'success' => true,
            'data' => [
                'token' => $token,
            ],
        ]);
}

```

and my **LoginUserAction** something like this:

```auto
    public function __invoke(LoginUserRequest $data): User
    {
        return $this->userModel->findByEmail($loginData->email);
    }

```

But how do i go about creating that custom request class? Is there any way in Slim? I tried finding a solution but havent found any yet.

And the custom **LoginUserRequest** something like this but i have no idea what to extend, implement or use to get there:

```auto
class LoginUserRequest
{
    public function __construct(
        public string $email,
        public string $password,
    ) {}

    public function __invoke($request) {
        $parsedBody = $request->getParsedBody();

        $this->email = $parsedBody['email'];

        $this->password = $parsedBody['password'];

        return $this;
    }
}

```

---

_[View the full topic](https://discourse.slimframework.com/t/slim-4-custom-request-extending-the-existing-request/4868)._
