1- [ ![ Build status] ( https://badge.buildkite.com/f74a461120ffcadbf7796d5aac8ae8c03a1cbcfda142220074.svg )] ( https://buildkite.com/theopenlane/httpsling )
1+ [ ![ Build status] ( https://badge.buildkite.com/f74a461120ffcadbf7796d5aac8ae8c03a1cbcfda142220074.svg )] ( https://buildkite.com/theopenlane/httpsling?branch=main )
22[ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=theopenlane_httpsling&metric=alert_status )] ( https://sonarcloud.io/summary/new_code?id=theopenlane_httpsling )
33[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/theopenlane/httpsling )] ( https://goreportcard.com/report/github.com/theopenlane/httpsling )
44[ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/theopenlane/httpsling.svg )] ( https://pkg.go.dev/github.com/theopenlane/httpsling )
@@ -33,7 +33,7 @@ func main() {
3333 }
3434
3535 // Perform a GET request
36- var out map [string ]interface {}
36+ var out map [string ]any
3737 resp , err := requester.Receive (&out, httpsling.Get (" resource" ))
3838 if err != nil {
3939 log.Fatal (err)
@@ -56,9 +56,17 @@ RequestWithContext(context.Context, ...Option) (*http.Request, error)
5656Send (...Option ) (*http.Response , error )
5757SendWithContext (context.Context , ...Option ) (*http.Response , error )
5858
59- // build and send the request and parse the response into an interface
60- Receive (interface {}, ...Option ) (*http.Response , []byte , error )
61- ReceiveWithContext (context.Context , interface {}, ...Option ) (*http.Response , error )
59+ // build and send the request and parse the response into a value
60+ Receive (any, ...Option ) (*http.Response , error )
61+ ReceiveWithContext (context.Context , any, ...Option ) (*http.Response , error )
62+
63+ // typed helper using generics
64+ ReceiveInto[T any](...Option ) (*http.Response , T , error )
65+ ReceiveIntoWithContext[T any](context.Context , ...Option ) (*http.Response , T , error )
66+
67+ // stream response body into an io.Writer
68+ ReceiveTo (io.Writer , ...Option ) (*http.Response , int64 , error )
69+ ReceiveToWithContext (context.Context , io.Writer , ...Option ) (*http.Response , int64 , error )
6270```
6371
6472### Configuring BaseURL
@@ -130,7 +138,7 @@ The library provides a `Receive` to construct and dispatch HTTP. Here are exampl
130138``` go
131139 resp , err := requester.ReceiveWithContext (context.Background (), &out,
132140 httpsling.Post (" /path" ),
133- httpsling.Body (map [string ]interface {} {" key" : " value" })
141+ httpsling.Body (map [string ]any {" key" : " value" })
134142 )
135143```
136144
@@ -139,7 +147,7 @@ The library provides a `Receive` to construct and dispatch HTTP. Here are exampl
139147``` go
140148 resp , err := requester.ReceiveWithContext (context.Background (), &out,
141149 httpsling.Put (" /path/123456" ),
142- httpsling.Body (map [string ]interface {} {" key" : " newValue" })
150+ httpsling.Body (map [string ]any {" key" : " newValue" })
143151 )
144152```
145153
@@ -187,6 +195,8 @@ log.Printf("Status Code: %d\n", resp.StatusCode)
187195log.Printf (" Response Data: %s \n " , out.Data )
188196```
189197
198+ Note: Receive fully reads the response into memory to unmarshal, and restores ` resp.Body ` so it remains readable by callers.
199+
190200### Evaluating Response Success
191201
192202To assess whether the HTTP request was successful:
@@ -210,4 +220,4 @@ This library was inspired by and built upon the work of several other HTTP clien
210220
211221## Contributing
212222
213- See [ contributing] ( .github/CONTRIBUTING.md ) for details.
223+ See [ contributing] ( .github/CONTRIBUTING.md ) for details.
0 commit comments