Simple REST API - Fiber Typing CST Test
Loading…
Simple REST API — Fiber Code
Demonstrates a simple Fiber application with routes for listing and creating Todo items.
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")
}Fiber Language Guide
Fiber is an Express-inspired web framework written in Go, designed for high performance, minimal memory footprint, and fast HTTP handling. It leverages Go’s concurrency model for scalable web applications and APIs.
Primary Use Cases
- ▸High-performance REST APIs
- ▸Microservices and cloud-native applications
- ▸Real-time web applications
- ▸Backend services for mobile and web clients
- ▸IoT and messaging platforms
Notable Features
- ▸High-performance routing and HTTP handling
- ▸Middleware chaining similar to Express.js
- ▸Supports JSON, templating engines, and WebSocket
- ▸Minimal memory footprint
- ▸Fast startup and execution times
Origin & Creator
Created by Amir Salihefendić in 2020, Fiber was inspired by Node.js’ Express framework and built for Go developers seeking simplicity and speed.
Industrial Note
Fiber is widely used in Go-based microservices, API backends, and real-time systems where low latency and high throughput are critical.