{"id":36881669,"url":"https://github.com/alexferl/zerohttp","last_synced_at":"2026-04-04T03:04:42.613Z","repository":{"id":311710838,"uuid":"1044676476","full_name":"alexferl/zerohttp","owner":"alexferl","description":"Zero-dependency Go HTTP framework with secure-by-default middleware, built-in validation, and RFC 9457 error responses","archived":false,"fork":false,"pushed_at":"2026-03-26T02:21:35.000Z","size":9555,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-26T03:47:01.939Z","etag":null,"topics":["go","golang","http-server","microservice","middleware","rest-api","rfc-9457","server-sent-events","web-framework","zerohttp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexferl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-26T03:48:05.000Z","updated_at":"2026-03-26T02:21:16.000Z","dependencies_parsed_at":"2026-03-26T03:03:26.240Z","dependency_job_id":null,"html_url":"https://github.com/alexferl/zerohttp","commit_stats":null,"previous_names":["alexferl/zerohttp"],"tags_count":74,"template":false,"template_full_name":null,"purl":"pkg:github/alexferl/zerohttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fzerohttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fzerohttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fzerohttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fzerohttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexferl","download_url":"https://codeload.github.com/alexferl/zerohttp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fzerohttp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31265523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T02:49:12.781Z","status":"ssl_error","status_checked_at":"2026-04-01T02:49:05.845Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","http-server","microservice","middleware","rest-api","rfc-9457","server-sent-events","web-framework","zerohttp"],"created_at":"2026-01-12T15:24:40.813Z","updated_at":"2026-04-01T19:02:16.355Z","avatar_url":"https://github.com/alexferl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zerohttp [![Go Reference](https://pkg.go.dev/badge/github.com/alexferl/zerohttp.svg)](https://pkg.go.dev/github.com/alexferl/zerohttp) [![Go Report Card](https://goreportcard.com/badge/github.com/alexferl/zerohttp)](https://goreportcard.com/report/github.com/alexferl/zerohttp) [![Coverage Status](https://coveralls.io/repos/github/alexferl/zerohttp/badge.svg?branch=master)](https://coveralls.io/github/alexferl/zerohttp?branch=master)\n\nA lightweight, secure-by-default HTTP framework for Go. Built on `net/http` with zero external dependencies.\n\n## Why zerohttp?\n\n**Built on stdlib, not instead of it.** zerohttp builds on Go's `net/http` rather than replacing it, so your handlers stay standard `http.HandlerFunc` and work with existing middleware and tooling.\n\n**Secure by default.** Sensible security headers, request body limits, panic recovery, and request IDs are applied automatically for every request.\n\n**Zero dependencies.** Single module, standard library only, so your service stays lean and easy to upgrade.\n\n**Handler errors that make sense.** Handlers return `error`, and RFC 9457 Problem Details responses are generated for you automatically.\n\n## Features\n\n- **Zero dependencies** - Single module, no external deps\n- **Secure by default** - Security headers, body limits, recovery, request IDs enabled automatically\n- **Standard library foundation** - Built on `net/http`, works with any `http.Handler` middleware\n- **Handler errors** - Return `error`, get proper HTTP responses automatically\n- **Request binding** - JSON, form, multipart, and query params to structs with struct tags\n- **Validation** - Built-in struct validation with 40+ validators\n- **Problem Details** - RFC 9457 compliant error responses\n- **Middleware** - CORS, rate limiting, auth, circuit breaker, and more\n- **Metrics** - Prometheus-compatible metrics at `/metrics`\n- **Lifecycle hooks** - Pre/post startup and shutdown hooks\n- **Pluggable** - Bring your own validator, tracer, HTTP/3, WebSocket, SSE\n\n## Installation\n\n```shell\ngo get github.com/alexferl/zerohttp\n```\n\nRequires Go 1.25 or later.\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"net/http\"\n\n    zh \"github.com/alexferl/zerohttp\"\n)\n\nfunc main() {\n    app := zh.New()\n\n    app.GET(\"/hello/{name}\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n        name := zh.Param(r, \"name\")\n        return zh.Render.JSON(w, http.StatusOK, zh.M{\"message\": \"Hello, \" + name + \"!\"})\n    }))\n\n    log.Fatal(app.Start())\n}\n```\n\n```shell\ngo run main.go\ncurl http://localhost:8080/hello/world\n{\"message\":\"Hello, world!\"}\n```\n\n## Examples\n\nSee the [`examples/`](examples/) directory for more complete examples.\n\n### Request Binding \u0026 Validation\n\n```go\ntype CreateUserRequest struct {\n    Name  string `json:\"name\" validate:\"required,min=2,max=50\"`\n    Email string `json:\"email\" validate:\"required,email\"`\n}\n\napp.POST(\"/users\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n    var req CreateUserRequest\n    if err := zh.BindAndValidate(r, \u0026req); err != nil {\n        return err // Automatic Problem Details response\n    }\n    // Process valid request...\n    return zh.R.JSON(w, http.StatusCreated, req)\n}))\n```\n\n### Route Groups with Middleware\n\n```go\napp.Group(func(api zh.Router) {\n    api.Use(basicauth.New(basicauth.Config{\n        Credentials: map[string]string{\"admin\": \"secret\"},\n    }))\n    api.GET(\"/admin/dashboard\", dashboardHandler)\n})\n```\n\n### Query Parameters\n\n```go\ntype SearchRequest struct {\n    Query string `query:\"q\" validate:\"required\"`\n    Limit int    `query:\"limit\" validate:\"max=100\"`\n}\n\napp.GET(\"/search\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n    var req SearchRequest\n    if err := zh.BindAndValidate(r, \u0026req); err != nil {\n        return err\n    }\n    return zh.R.JSON(w, http.StatusOK, zh.M{\"results\": []string{}})\n}))\n```\n\n### Error Handling\n\n```go\napp.GET(\"/users/{id}\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n    id := zh.Param(r, \"id\")\n    user, err := db.GetUser(id)\n    if err != nil {\n        problem := zh.NewProblemDetail(http.StatusNotFound, \"user not found\")\n        return zh.R.ProblemDetail(w, problem)\n    }\n    return zh.R.JSON(w, http.StatusOK, user)\n}))\n```\n\n### Response Helpers\n\n```go\napp.GET(\"/health\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n    return zh.R.Text(w, http.StatusOK, \"healthy\")\n}))\n\napp.GET(\"/docs\", zh.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {\n    return zh.R.Redirect(w, r, \"https://pkg.go.dev/github.com/alexferl/zerohttp\", http.StatusFound)\n}))\n```\n\n## Configuration\n\nzerohttp uses struct-based configuration:\n\n```go\napp := zh.New(zh.Config{\n    Addr: \":8080\",\n    TLS: zh.TLSConfig{\n        Addr:     \":8443\",\n        CertFile: \"cert.pem\",\n        KeyFile:  \"key.pem\",\n    },\n    RequestBodySize: requestbodysize.Config{\n        MaxBytes: 5 * 1024 * 1024, // 5MB\n    },\n})\n```\n\n## Secure by Default\n\nThese middlewares are applied automatically:\n\n- **Request ID** - Unique IDs for tracing\n- **Panic Recovery** - Graceful panic handling with stack traces\n- **Request Body Size Limits** - DoS protection (1MB default)\n- **Security Headers** - CSP, HSTS, X-Frame-Options, etc.\n- **Request Logging** - Structured request/response logging\n\nDisable or customize via `zh.Config`.\n\n## Storage\n\nThe `storage` package provides a shared interface for middleware storage backends. Implement `storage.Storage` once (for Redis, PostgreSQL, etc.) and reuse it across multiple middlewares via adapters:\n\n```go\nimport (\n    \"github.com/alexferl/zerohttp/middleware/cache\"\n    \"github.com/alexferl/zerohttp/middleware/idempotency\"\n    \"github.com/alexferl/zerohttp/storage\"\n)\n\n// Implement storage.Storage and storage.Locker in your own package\ntype MyRedis struct { /* ... */ }\nfunc (r *MyRedis) Get(ctx context.Context, key string) ([]byte, bool, error) { /* ... */ }\nfunc (r *MyRedis) Set(ctx context.Context, key string, val []byte, ttl time.Duration) error { /* ... */ }\nfunc (r *MyRedis) Delete(ctx context.Context, key string) error { /* ... */ }\nfunc (r *MyRedis) Lock(ctx context.Context, key string, ttl time.Duration) (bool, error) { /* ... */ }\nfunc (r *MyRedis) Unlock(ctx context.Context, key string) error { /* ... */ }\n\n// One backend, multiple middlewares\nredis := \u0026MyRedis{}\n\napp.Use(cache.New(cache.Config{\n    Store: cache.NewStorageAdapter(redis),\n}))\n\nidempotencyStore, _ := idempotency.NewStorageAdapter(redis)\napp.Use(idempotency.New(idempotency.Config{\n    Store: idempotencyStore,\n}))\n```\n\n## Testing\n\nThe `zhtest` package provides fluent test helpers:\n\n```go\nfunc TestGetUser(t *testing.T) {\n    app := setupRouter()\n    req := zhtest.NewRequest(http.MethodGet, \"/users/123\").Build()\n    w := zhtest.Serve(app, req)\n    zhtest.AssertWith(t, w).Status(http.StatusOK).JSONPathEqual(\"name\", \"John\")\n}\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fzerohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexferl%2Fzerohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fzerohttp/lists"}