Getting Started with Rue
Rue is a high-performance, feature-rich web framework for Go with minimal dependencies. It's designed to be fast, flexible, and easy to use.
Features
- Blazing Fast Router - Radix tree-based routing with ~8ns static route matching
- Rich Middleware - Logger, Recovery, CORS, Rate Limiter, JWT, API Key
- Data Binding - JSON, XML, Form, Query binding with validation
- WebSocket - Full RFC 6455 implementation with Hub for broadcasting
- SSE - Server-Sent Events support
- GraphQL - Built-in GraphQL handler with Playground
- gRPC - Seamless gRPC integration with middleware adapter
- QUIC/HTTP3 - Next-generation protocol support
- Compression - Gzip and Brotli with auto-negotiation
Installation
Rue requires Go 1.21 or later. Install it using go get:
bash
go get github.com/ch-hash-lab/rue
Quick Start
Create a new file main.go:
go
package main
import (
"net/http"
"github.com/ch-hash-lab/rue"
)
func main() {
// Create engine with default middleware (Logger + Recovery)
r := rue.Default()
// Simple route
r.GET("/", func(c *rue.Context) {
c.JSON(http.StatusOK, rue.H{"message": "Hello, Rue!"})
})
// Path parameters
r.GET("/users/:id", func(c *rue.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, rue.H{"user_id": id})
})
// Query parameters
r.GET("/search", func(c *rue.Context) {
q := c.Query("q")
page := c.DefaultQuery("page", "1")
c.JSON(http.StatusOK, rue.H{"query": q, "page": page})
})
// Start server
r.Run(":8080")
}
Run your application:
bash
go run main.go
Visit http://localhost:8080 in your browser!
Engine Modes
Rue provides two ways to create an engine:
Default()
Creates an engine with Logger and Recovery middleware pre-configured:
go
r := rue.Default() // Includes Logger + Recovery
New()
Creates a blank engine without any middleware:
go
r := rue.New() // No middleware
r.Use(rue.Logger()) // Add manually
r.Use(rue.Recovery())
💡 Tip
Use Default() for most applications. Use New() when you need full control over middleware.
Next Steps
- Learn about Routing and path parameters
- Explore Middleware options
- Set up Data Binding and validation
- Add real-time features with WebSocket