# Controllers

A controller is a class that manages the logic for handling requests and responses from clients. Controllers separate the handling code for better structure and easier maintenance.

## Simple Controller (ExampleController.ts)

```javascript
import { Controller, Request, Response } from 'fhyts';

export class ExampleController extends Controller {

  // Method that handles GET requests to the main page
  async index(req: Request, res: Response) {
    // Sends a simple text response with status 200 OK
    return res.status(200).send('Welcome to FhyTS!');
  }

}
```

## Explanation:

* **Controller** is extended to use the framework's built-in features.
* **index** is the method that will be executed when a specific route calls this controller.
* **req** is the request object containing the request data from the client.
* **res** is the response object used to send a reply to the client.
* **res.status(200).send()** sends an HTTP status of 200 (OK) and text as a response.

## Controller Usage

Typically, controllers are invoked by routing, for example:

```javascript
import { ExampleController } from './ExampleController';

export function Route() {
  const Example = new ExampleController();

  Use('GET', '/', (req, res) => Example.index(req, res));
}
```

## Next,

You can proceed to [Templating](#templating) to manage the rendering of dynamic HTML pages in your application.