A Go library for bi-directional data binding between HTTP requests and Go structs, decoding requests and encoding structs into requests.
httpin is a Go library that provides bi-directional data binding between Go structs and HTTP requests. It automatically decodes HTTP input (query parameters, headers, form data, JSON/XML bodies, path variables, and file uploads) into structs and encodes structs into HTTP requests, eliminating manual parsing boilerplate for faster and more maintainable API development.
Go developers building HTTP servers or clients, especially those using frameworks like net/http, go-chi/chi, gorilla/mux, or gin-gonic/gin who want to reduce repetitive input/output handling code.
Developers choose httpin because it offers a declarative, struct-tag-based approach that works across multiple HTTP frameworks, supports both request decoding and encoding, and is extensible with custom directives, leading to cleaner, more readable, and less error-prone code compared to manual parsing.
🍡 HTTP Input for Go - HTTP Request from/to Go Struct (Bi-directional Data Binding between Go Struct and http.Request)
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Decodes from query parameters, headers, form data, JSON/XML bodies, path variables, and file uploads in one go, eliminating manual parsing for diverse HTTP data types as shown in the Core Features list.
Supports both decoding requests into structs and encoding structs into HTTP requests via httpin.NewRequest, making it useful for building client SDKs alongside server handlers, as demonstrated in the encoding example.
Openly integrates with net/http, go-chi/chi, gorilla/mux, gin-gonic/gin, and others, allowing seamless adoption across various Go HTTP setups without lock-in.
Allows adding custom directives for advanced use cases, providing flexibility beyond built-in features, though it requires understanding of httpin's internals as noted in the documentation.
Uses `in` struct tags to define mappings, defaults, and optional values, reducing boilerplate and improving code readability compared to manual net/http parsing, as illustrated in the comparison table.
Errors in struct tags (e.g., typos in field names) are only caught at runtime, leading to potential bugs that aren't caught during compilation, unlike type-safe alternatives.
Focuses on parsing and binding, but validation of input data (e.g., format checks, business rules) requires additional libraries or custom code, which isn't a highlighted core feature.
The use of reflection for struct parsing can introduce performance overhead compared to hand-optimized code, which might be a concern for high-traffic applications, though it's a trade-off for convenience.