Type-Safe HTTP Framework for Go. Define Types. Derive Everything.
Build APIs where struct types are the single source of truth. Validation, OpenAPI 3.1.0 specs, error contracts, and interactive docs all generated automatically from your Go types — on a stdlib foundation.
Getting Startedimport "github.com/zoobz-io/rocco"
type CreateOrderInput struct {
CustomerID string `json:"customer_id" description:"Customer UUID"`
Total float64 `json:"total" description:"Order total"`
}
type OrderOutput struct {
ID string `json:"id"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
}
// Define once — validation, OpenAPI, and docs derived automatically
engine := rocco.New()
rocco.POST[CreateOrderInput, OrderOutput]("/orders",
func(req *rocco.Request[CreateOrderInput]) (OrderOutput, error) {
body := req.Body() // Typed, validated
return OrderOutput{
ID: uuid.New().String(),
Status: "created",
CreatedAt: time.Now(),
}, nil
},
).WithSuccessStatus(201).
WithErrors(ErrInvalidOrder, ErrCustomerNotFound).
Register(engine)
// OpenAPI at /openapi, interactive docs at /docs
engine.Run(":8080")Why Rocco?
One type definition drives validation, documentation, and error contracts.
Contract-First by Default
Struct types are the single source of truth. OpenAPI schemas, validation rules, and error contracts all derived — never out of sync.
Automatic OpenAPI 3.1.0
Specs generated at handler registration. Served at /openapi with interactive docs at /docs. No separate schema files.
Built-In Validation
Opt-in via Validatable interface. Struct tag constraints and cross-field checks run before your handler sees the data.
Stdlib Foundation
Built on Go 1.22+ http.ServeMux with native path parameters. No heavy external router — direct access to the underlying mux.
First-Class SSE Streaming
Server-Sent Events with typed Stream[T] interface. Real-time data flows are a core feature, not an afterthought.
Declared Error Contracts
Handlers must declare their errors. Undeclared errors log warnings and return 500 — no silent failures in production.
Capabilities
Type-safe handlers, automatic documentation, authentication, and streaming on a stdlib foundation.
| Feature | Description | Link |
|---|---|---|
| Type-Safe Handlers | Generic handlers with compile-time input/output checking. NoBody for bodyless requests, path and query parameters. | Handlers |
| Error Handling | Sentinel errors with structured JSON responses. Error types declared per handler, auto-documented in OpenAPI. | Errors |
| Authentication | Built-in identity extraction, scope-based authorization, and role-based access control middleware. | Authentication |
| OpenAPI Generation | Schema generation from types at registration time. Customizable with descriptions, examples, and overrides. | OpenAPI |
| Server-Sent Events | Typed Stream[T] interface for real-time data. Heartbeats, reconnection, and graceful shutdown built in. | Streaming |
| Lifecycle Events | Capitan signals for request received, handler executing, errors, and completion. Full observability hooks. | Observability |
Articles
Browse the full rocco documentation.