Repository navigation
HTTPClient v2.0.0
·
51 commits
to main
since this release
Breaking Changes
- Removes implicit error fields. Functions now return
(T, error)so errors must be handled directly. - Request helpers now return the decoded value instead of a wrapper type, keeping usage simple and closer to typical Go APIs.
- All request helpers (
Get,Post,Put, etc.) use the same function signature. - Several legacy abstractions were removed, making the client easier to understand and maintain.
- Errors work naturally with
errors.Is, requests respect context cancellation, and middleware/logging integrate cleanly. - Simplifies the internal design and provides a cleaner base for future features.
API Changes Before/After
Before (v1 - implicit errors, wrapped result)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
res := httpx.Get[User](client, "https://api.example.com/users/1")
if res.Err != nil {
log.Fatal(res.Err)
}
fmt.Println(res.Body.Name)Problems
- Error is hidden inside a wrapper
- Easy to forget to check
res.Err - Forces consumers to learn a custom response type
After (v2 - explicit, idiomatic Go)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
user, err := httpx.Get[User](client, "https://api.example.com/users/1")
if err != nil {
log.Fatal(err)
}
fmt.Println(user.Name)Improvements
- Errors are explicit and unavoidable
- Return values match standard Go expectations
- Cleaner, more readable call sites
Before (v1 - POST with response wrapper)
res := httpx.Post[CreateUser, User](client, "/users", CreateUser{Name: "Ana"})
if res.Err != nil {
log.Fatal(res.Err)
}
fmt.Println(res.Body)After (v2 - explicit input/output)
user, err := httpx.Post[CreateUser, User](client, "/users", CreateUser{Name: "Ana"})
if err != nil {
log.Fatal(err)
}
fmt.Println(user)Before (v1 - response wrapper access)
res := httpx.Get[User](client, "/users/1")
status := res.Response.StatusCodeAfter (v2 - explicit access via Do)
req := httpx.NewRequest("GET", "/users/1")
user, resp, err := httpx.Do[User](req)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.StatusCode)Summary
- No hidden error fields
- No wrapper structs
- Explicit, idiomatic Go APIs
- Easier to reason about and compose
This change makes the library safer, simpler, and more predictable without sacrificing power.
This snapshot preserves the original Httpx history. For the installable HTTPClient module, see HTTPClient v0.1.0.