Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/01-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This example demonstrates the most basic usage of Fox framework.
## Features

- Simple GET endpoint
- Path parameters
- Path parameters (two methods: `ctx.Param()` and struct binding)
- Automatic JSON response rendering

## Running
Expand All @@ -20,9 +20,12 @@ go run main.go
# Test ping endpoint
curl http://localhost:8080/ping

# Test parameterized endpoint
# Test parameterized endpoint - using ctx.Param()
curl http://localhost:8080/hello/world

# Test parameterized endpoint - using struct binding
curl http://localhost:8080/greet/alice

# Test POST endpoint
curl -X POST http://localhost:8080/echo
```
Expand All @@ -36,6 +39,9 @@ pong
# /hello/world
Hello, world!

# /greet/alice
Greetings, alice!

# /echo
{"message":"Echo service is working"}
```
10 changes: 9 additions & 1 deletion examples/01-basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ func main() {
return "pong"
})

// GET with path parameter
// GET with path parameter - using ctx.Param()
router.GET("/hello/:name", func(ctx *fox.Context) string {
name := ctx.Param("name")
return "Hello, " + name + "!"
})

// GET with path parameter - using struct binding
type UserParams struct {
Name string `uri:"name" binding:"required"`
}
router.GET("/greet/:name", func(params UserParams) string {
return "Greetings, " + params.Name + "!"
})

// POST endpoint returning JSON
router.POST("/echo", func() map[string]string {
return map[string]string{
Expand Down
Loading