# Request

The Request object in FhyTS is an abstraction of **http.IncomingMessage** that has been simplified and extended to facilitate the management of HTTP request data.

## Access Common Properties

Here are the main properties and methods available from the Request object:

| Property / Method | Type | Description |
| ----------------- | --------------------------------------- | -------------------------------------------------------------- |
| `method` | `string` | HTTP methods such as `GET`, `POST`, etc. |
| `url` | `string` | The original URL of the request. |
| `headers` | `IncomingHttpHeaders` | The headers of the request. |
| `body` | `any` | The body of the request. Must be parsed first. |
| `params` | `Record<string, string>` | Dynamic parameters from the URL (e.g., `/user/:id`). |
| `query` | `Record<string, string>` | Query parameters from the URL (`?key=value`). |
| `cookies` | `Record<string, string>` | Cookies sent by the client. |
| `getHeader(name)` | `(name: string) => string \| undefined` | Retrieves the value of a specific header. |
| `parseBody()` | `Promise<void>` | Parses the `body` content for POST/PUT/PATCH methods. |

## Usage Examples

**Accessing Basic Information**

```javascript
export const index = async (req: Request, res: Response) => {
  const method = req.method;
  const userAgent = req.getHeader('user-agent');
  const query = req.query;

  res.json({ method, userAgent, query });
};
```

## Parsing the Body (POST)

Before accessing **req.body**, be sure to call **parseBody()** first:

```javascript
export const store = async (req: Request, res: Response) => {
  await req.parseBody(); // Required for body parser

  const { name, email } = req.body;
  res.json({ received: { name, email } });
};
```

## Accessing Parameters and Queries

```javascript
// Route: /users/:id
export const show = async (req: Request, res: Response) => {
  const userId = req.params.id;
  const lang = req.query.lang || 'en';

  res.json({ userId, lang });
};
```

## Accessing Cookies

```javascript
export const profile = async (req: Request, res: Response) => {
  const session = req.cookies['session_id'];
  res.json({ session });
};
```

## Integration

The **Request** object is automatically available across controllers and middleware via the **req** parameter. It does not need to be manually initialized by the application developer.

## Best Practices

* Always call **await req.parseBody()** for **POST**, **PUT**, or **PATCH** methods before accessing **req.body**.
* Explicitly validate the contents of **body** or **params** according to business needs.
* Avoid storing large amounts of data in **req** during chained middleware processes.

## Next

Now that you understand how to use [Response](#response ), you can move on to the Response section to learn how to manage HTTP responses in your application.