Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 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 (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-22T04:21:25.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T00:43:09.701Z (5 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
======[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/valord577/httpc?t=2)](https://goreportcard.com/report/github.com/valord577/httpc)
[![Go Reference](https://pkg.go.dev/badge/github.com/valord577/httpc.svg)](https://pkg.go.dev/github.com/valord577/httpc)
[![GitHub](https://img.shields.io/github/license/valord577/httpc?t=0)](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).