Learn FIBER with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Fiber Simple REST API
package main
import (
"github.com/gofiber/fiber/v2"
)
type Todo struct {
ID int `json:"id"`
Title string `json:"title"`
Completed bool `json:"completed"`
}
var todos []Todo
func main() {
app := fiber.New()
app.Get("/todos", func(c *fiber.Ctx) error {
return c.JSON(todos)
})
app.Post("/todos", func(c *fiber.Ctx) error {
var todo Todo
if err := c.BodyParser(&todo); err != nil {
return err
}
todos = append(todos, todo)
return c.Status(201).JSON(todo)
})
app.Listen(":3000")
}
Demonstrates a simple Fiber application with routes for listing and creating Todo items.