Skip to content

Commit f29d0a0

Browse files
committed
docs: Controller documentation
1 parent 77829e0 commit f29d0a0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

documentation/docs/guides/controllers.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,36 @@ import FlowChart from '@site/src/components/FlowChart';
44

55
Controllers are the main way to interact with the application. They are responsible for handling the requests and responses.
66

7+
8+
79
<FlowChart selected="Controller" />
10+
11+
## Controller types
12+
13+
### Returning JSON
14+
15+
```go
16+
func (c *fuego.ContextNoBody) (MyResponse, error)
17+
```
18+
19+
Used when the request does not have a body. The response will be automatically serialized to JSON.
20+
21+
```go
22+
func (c *fuego.ContextWithBody[MyInput]) (MyResponse, error)
23+
```
24+
25+
Used when the request has a body.
26+
Fuego will automatically parse the body and validate it using the input struct.
27+
28+
### Returning HTML
29+
30+
```go
31+
func (c *fuego.ContextNoBody) (fuego.HTML, error)
32+
```
33+
34+
Some special interface return types are used by Fuego to return special responses.
35+
36+
- `fuego.HTML` is used to return HTML responses from `html/template`.
37+
- `fuego.Templ` is used to return HTML responses from `a-h/templ`.
38+
- `fuego.Gomponent` is used to return HTML responses from `maragudk/gomponent`.
39+

0 commit comments

Comments
 (0)