renderer
April 22, 2026 ยท View on GitHub
A minimal, fast, and production-ready HTTP response renderer for Go.
It provides a clean abstraction over net/http responses with support for JSON, XML, Text, Bytes, Files, and a safe handler adapter compatible with Chi and standard library HTTP.
โจ Features
- โก Zero-dependency core (stdlib only)
- ๐ง Clean Response abstraction
- ๐ Panic-safe HTTP handler wrapper
- ๐ฆ JSON / XML / Text / Bytes / File responses
- ๐ Streaming file support (no memory overload)
- ๐ง Header support on all responses
- ๐งฉ Chi / net/http compatible
- ๐งช Fully testable design
๐ฆ Installation
go get github.com/thedevsaddam/renderer/v2
๐ Quick Start
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/thedevsaddam/renderer/v2"
)
func main() {
r := chi.NewRouter()
r.Get("/hello", renderer.Handle(func(r *http.Request) (renderer.Response, error) {
return renderer.JSON(200, map[string]string{
"message": "hello renderer v2",
}), nil
}))
http.ListenAndServe(":8080", r)
}
๐ค JSON Response
renderer.JSON(200, map[string]string{
"name": "Saddam",
})
With indentation
renderer.JSON(200, data).Indent()
Add headers
renderer.JSON(200, data).
Header("X-App", "renderer")
๐ Text Response
renderer.Text(200, "hello world")
๐ XML Response
type User struct {
Name string `xml:"name"`
}
renderer.XML(200, User{Name: "Saddam"})
๐ฆ Raw Bytes
renderer.Bytes(200, []byte("hello"), "application/octet-stream")
๐ File Streaming
Download file
file := strings.NewReader("file content")
renderer.File(200, file, "report.txt")
Inline file
renderer.File(200, file, "report.txt").Inline()
โ๏ธ Handler Adapter
type HandlerFunc func(r *http.Request) (Response, error)
r.Get("/ping", renderer.Handle(func(r *http.Request) (renderer.Response, error) {
return renderer.JSON(200, map[string]any{
"ping": "pong",
}), nil
}))
๐ฅ Panic Safety
All handlers are automatically protected from panics and return HTTP 500 safely.
๐ง Design Philosophy
- Explicit over magic
- Composition over framework lock-in
- Streaming-first design
- Minimal API surface
๐งช Testing
go test ./...
โก Benchmarks
go test ./... -bench=.
๐ License
MIT