Fiber — Express-Inspired Web Framework Written in Go
Fiber is an Express-inspired web framework written in Go, built on top of Fasthttp — the fastest HTTP engine for Go. Familiar Express-like API, zero memory allocation routing, built-in middleware, and WebSocket support.
Instalación con revisión previa
Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.
npx -y tokrepo@latest install 65c0e1cd-3630-11f1-9bc6-00163e2b0d79 --target codexPrimero dry-run, confirma las escrituras y luego ejecuta este comando.
What it is
Fiber is a web framework written in Go, inspired by Express.js. Built on top of Fasthttp (the fastest HTTP engine for Go), it offers a familiar Express-like API with zero-allocation routing, built-in middleware, WebSocket support, and rate limiting. Developers coming from Node.js can transition to Go with minimal API learning curve.
This tool is for backend developers who want Go's performance and type safety with an API design they already know from Express. It is also for Go developers who want a batteries-included framework.
How it saves time or tokens
Fiber's Express-like API reduces the learning curve for Node.js developers moving to Go. Route definitions, middleware chaining, and request handling follow the same patterns. The built-in middleware covers common needs (CORS, compression, logging, rate limiting) without third-party packages.
How to use
- Initialize a Go module and install Fiber.
- Define routes with familiar Express-like syntax.
- Add middleware as needed.
- Run the server.
# Initialize project
mkdir myapi && cd myapi
go mod init myapi
go get github.com/gofiber/fiber/v2
Example
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
app := fiber.New()
// Middleware
app.Use(logger.New())
app.Use(cors.New())
// Routes
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"message": "Hello, Fiber"})
})
app.Get("/users/:id", func(c *fiber.Ctx) error {
id := c.Params("id")
return c.JSON(fiber.Map{"id": id, "name": "Alice"})
})
app.Post("/users", func(c *fiber.Ctx) error {
type User struct {
Name string `json:"name"`
Email string `json:"email"`
}
user := new(User)
if err := c.BodyParser(user); err != nil {
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
}
return c.Status(201).JSON(user)
})
app.Listen(":3000")
}
Related on TokRepo
- AI coding tools — Backend development tools
- Automation tools — API and server automation
Common pitfalls
- Fiber uses Fasthttp, not net/http. This means some net/http middleware and libraries are not directly compatible.
- The
*fiber.Ctxis reused across requests for performance. Do not store references to it beyond the handler scope. - Fiber's request body parsing requires struct tags. Missing or incorrect tags cause silent parsing failures.
- Error handling differs from Express. Always return errors from handlers; unhandled panics crash the server.
- WebSocket handling in Fiber requires the separate
github.com/gofiber/websocketpackage. - Review the official documentation before deploying to production to ensure compatibility with your specific environment and requirements.
- Start with default settings and customize incrementally. Changing too many configuration options at once makes debugging harder.
- Keep your installation updated to the latest stable version. Security patches and bug fixes are released regularly.
Preguntas frecuentes
Fiber on Go with Fasthttp is significantly faster than Express on Node.js. Benchmarks typically show 10-20x higher throughput for JSON responses. Go's compiled nature and Fasthttp's zero-allocation design drive the performance gap.
Not directly. Fiber uses Fasthttp instead of net/http. However, adapters exist to wrap net/http handlers for use with Fiber. The built-in middleware covers most common needs.
Yes. Fiber supports WebSockets through the gofiber/websocket package. It integrates with Fiber's routing and middleware system.
Yes. Fiber works with any Go ORM including GORM, Ent, and sqlx. Define your models and database connection in your application, and use them in Fiber handlers.
Fiber is built on Fasthttp (faster) with an Express-like API. Gin is built on net/http (more compatible with the Go ecosystem). Choose Fiber for maximum performance and Express familiarity, Gin for broader middleware compatibility.
Referencias (3)
- Fiber GitHub— Fiber is an Express-inspired web framework for Go
- Fiber Documentation— Fiber documentation and API reference
- Fasthttp GitHub— Fasthttp high-performance HTTP engine for Go
Relacionados en TokRepo
Discusión
Activos relacionados
Express — Fast Unopinionated Minimalist Web Framework for Node.js
Express is the original, most popular web framework for Node.js. Minimal, flexible, and the foundation of countless APIs. The go-to starting point for Node.js backends that inspired Koa, Hono, Fastify, and many others.
Loco — Rails-Inspired Web Framework for Rust
Loco is a Rust web framework modeled after Ruby on Rails, providing generators, ORM, background jobs, mailers, and authentication out of the box for rapid full-stack development.
Ginkgo — BDD Testing Framework for Go
An expressive BDD-style testing framework for Go with support for spec nesting, lifecycle hooks, parallel execution, and structured test output. Pairs with the Gomega matcher library.
Koa — Expressive Middleware Framework for Node.js
Koa is a web framework for Node.js designed by the team behind Express. It uses async/await natively for cleaner middleware composition and a smaller, more expressive core.