# Controller

<figure><img src="/files/VpT6zfcNTk0l0pzlMhyQ" alt=""><figcaption></figcaption></figure>

A controller's purpose is to receive specific requests for the application. The **routing** mechanism controls which controller receives which requests. Frequently, each controller has more than one route, and different routes can perform different actions.

Syntax for create controller in Tinh Tinh:

```go
package app

import "github.com/tinh-tinh/tinhtinh/core"

func Controller(module *core.DynamicModule) *core.DynamicController {
    ctrl := module.NewController("users")
    
    ctrl.Get("", func (ctx core.Ctx) {
        ctx.JSON(core.Map{
            "data": "ok"
        })
    })
    
    return ctrl
}
```

Method available in controller

| Method                        | Description                                                                |
| ----------------------------- | -------------------------------------------------------------------------- |
| Use(...Middleware)            | function for common middleware                                             |
| Guard(...Guard)               | function for check forbidden as middleware                                 |
| Version(string)               | function mark version for controller or routes                             |
| Registry()                    | function registry for group middleware to use for all routes in controller |
| Pipe(...Pipe)                 | validate and transform dto                                                 |
| Get(string, Handler)          | registry Get Http                                                          |
| Post(string, Handler)         | registry Post Http                                                         |
| Put(string, Handler)          | registry Put Http                                                          |
| Patch(string, Handler)        | registry Patch Http                                                        |
| Delete(string, Handler)       | registry Delete Http                                                       |
| Handler(string, http.Handler) | registry Handler for pure http.Handler                                     |
| Inject(Provide)               | get provider with name in module                                           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://elchemist.gitbook.io/tinh-tinh/core-fundamental/controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
