A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.
- Go 1.14 or higher.
- Simple and easy to use
- Make HTTP calls customizable
go mod:
go get github.com/valord577/httpc
- Do HTTP calls
package main
import (
"fmt"
"net/http"
"github.com/valord577/httpc"
)
func main() {
c := httpc.PackedReq{
URL: "https://www.google.com",
Method: http.MethodGet,
ReqBodyPublisher: httpc.PublisherNoBody{},
RespBodyHandler: httpc.RespBodyAsByteArray{},
}
bs, err := c.Send()
if err != nil {
panic(err)
}
fmt.Printf("%s", bs)
}
- Customize the processing of response body
package main
import (
"fmt"
"io"
"net/http"
"github.com/valord577/httpc"
)
type RespBodyAsString struct {}
func (r RespBodyAsString) Apply(body io.ReadCloser) (interface{}, error) {
bs, err := io.ReadAll(body)
if err != nil {
return nil, err
}
return string(bs), nil
}
func main() {
c := httpc.PackedReq{
URL: "https://www.google.com",
Method: http.MethodGet,
ReqBodyPublisher: httpc.PublisherNoBody{},
RespBodyHandler: RespBodyAsString{},
}
bs, err := c.Send()
if err != nil {
panic(err)
}
fmt.Printf("%s", bs)
}
See the CHANGES for changes.
See the LICENSE for Rights and Limitations (MIT).