https://github.com/valord577/httpc
A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.
https://github.com/valord577/httpc
go http-client
Last synced: 2 months ago
JSON representation
A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.
- Host: GitHub
- URL: https://github.com/valord577/httpc
- Owner: valord577
- License: mit
- Archived: true
- Created: 2021-08-11T12:26:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-22T04:21:25.000Z (over 3 years ago)
- Last Synced: 2024-08-03T19:10:00.240Z (11 months ago)
- Topics: go, http-client
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGE.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-extra - ARCHIVED - 08-11T12:26:27Z|2021-11-22T04:21:25Z| (Networking / HTTP Clients)
README
Httpc
======[](https://github.com/avelino/awesome-go)
[](https://goreportcard.com/report/github.com/valord577/httpc)
[](https://pkg.go.dev/github.com/valord577/httpc)
[](LICENSE)A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.
Requirements
------- Go 1.14 or higher.
Features
------- Simple and easy to use
- Make HTTP calls customizableInstalling
------go mod:
```shell
go get github.com/valord577/httpc
```Example
------- Do HTTP calls
```go
package mainimport (
"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
```go
package mainimport (
"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)
}
```Changes
------See the [CHANGES](CHANGE.md) for changes.
License
------See the [LICENSE](LICENSE) for Rights and Limitations (MIT).