https://github.com/rluders/httpsuite
A Go library to simplify request parsing, validation, and response handling in microservices, making code cleaner and more maintainable.
https://github.com/rluders/httpsuite
golang golang-package requests response rest validation
Last synced: 8 months ago
JSON representation
A Go library to simplify request parsing, validation, and response handling in microservices, making code cleaner and more maintainable.
- Host: GitHub
- URL: https://github.com/rluders/httpsuite
- Owner: rluders
- License: mit
- Created: 2024-11-09T13:19:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-08T11:53:47.000Z (12 months ago)
- Last Synced: 2025-09-29T12:34:03.454Z (9 months ago)
- Topics: golang, golang-package, requests, response, rest, validation
- Language: Go
- Homepage: https://pkg.go.dev/github.com/rluders/httpsuite/v2
- Size: 41 KB
- Stars: 36
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go-with-stars - httpsuite - only core and optional validation. | 2026-05-01 | (Web Frameworks / Utility/Miscellaneous)
- awesome-go - httpsuite - HTTP request parsing and RFC 9457 problem responses for Go, with a stdlib-only core and optional validation. (Web Frameworks / Utility/Miscellaneous)
- fucking-awesome-go - httpsuite - HTTP request parsing and RFC 9457 problem responses for Go, with a stdlib-only core and optional validation. (Web Frameworks / Utility/Miscellaneous)
README
# httpsuite
httpsuite is a lightweight, idiomatic Go library that simplifies HTTP request parsing, validation,
and response handling in microservices. Itβs designed to reduce boilerplate and promote clean,
maintainable, and testable code β all while staying framework-agnostic.
## β¨ Features
- π§Ύ **Request Parsing**: Automatically extract and map JSON payloads and URL path parameters to Go structs.
- β
**Validation:** Centralized validation using struct tags, integrated with standard libraries like `go-playground/validator`.
- π¦ **Unified Responses:** Standardize your success and error responses (e.g., [RFC 7807 Problem Details](https://datatracker.ietf.org/doc/html/rfc7807)) for a consistent API experience.
- π **Modular Design:** Use each component independently β ideal for custom setups, unit testing, or advanced use cases.
- π§ͺ **Test-Friendly:** Decouple parsing and validation logic for simpler, more focused test cases.
### π Supported routers
- [Chi](https://github.com/go-chi/chi)
- [Gorilla MUX](https://github.com/gorilla/mux)
- Go standard `http.ServeMux`
- ...and potentially more β [Submit a PR with an example!](https://github.com/rluders/httpsuite)
## π Installation
To install **httpsuite**, run:
```
go get github.com/rluders/httpsuite/v2
```
## π Usage
```go
import (
"github.com/go-chi/chi/v5"
"github.com/rluders/httpsuite/v2"
"net/http"
)
type SampleRequest struct {
ID int `json:"id" validate:"required"`
Name string `json:"name" validate:"required,min=3"`
}
func (r *SampleRequest) SetParam(fieldName, value string) error {
if fieldName == "id" {
id, err := strconv.Atoi(value)
if err != nil {
return err
}
r.ID = id
}
return nil
}
func main() {
r := chi.NewRouter()
r.Post("/submit/{id}", func(w http.ResponseWriter, r *http.Request) {
req, err := httpsuite.ParseRequest[*SampleRequest](w, r, chi.URLParam, "id")
if err != nil {
return // ProblemDetails already sent
}
httpsuite.SendResponse(w, http.StatusOK, req, nil, nil)
})
http.ListenAndServe(":8080", r)
}
```
π‘ Try it:
```
curl -X POST http://localhost:8080/submit/123 \
-H "Content-Type: application/json" \
-d '{"name":"John"}'
```
## π Examples
Check out the `examples/` folder for a complete working project demonstrating:
- Full request lifecycle
- Param parsing
- Validation
- ProblemDetails usage
- JSON response formatting
## π Tutorial & Article
- [Improving Request Validation and Response Handling in Go Microservices](https://medium.com/@rluders/improving-request-validation-and-response-handling-in-go-microservices-cc54208123f2)
## π€ Contributing
All contributions are welcome! Whether it's a bug fix, feature proposal, or router integration example:
- Open an issue
- Submit a PR
- Join the discussion!
## πͺͺ License
The MIT License (MIT). Please see [License File](LICENSE) for more information.