https://github.com/x-mod/httpclient
http client with smooth interfaces
https://github.com/x-mod/httpclient
http http-client request response
Last synced: 26 days ago
JSON representation
http client with smooth interfaces
- Host: GitHub
- URL: https://github.com/x-mod/httpclient
- Owner: x-mod
- License: mit
- Created: 2019-05-02T00:40:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-04T07:15:38.000Z (almost 5 years ago)
- Last Synced: 2024-06-21T08:13:30.449Z (over 1 year ago)
- Topics: http, http-client, request, response
- Language: Go
- Size: 36.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
httpclient
===
[](https://travis-ci.org/x-mod/httpclient) [](https://goreportcard.com/report/github.com/x-mod/httpclient) [](https://coveralls.io/github/x-mod/httpclient?branch=master) [](https://godoc.org/github.com/x-mod/httpclient)
More smooth package for http operations as a client:
- http request builder
- http response processor
- http client extension
### http.Request Builder
````go
import "github.com/x-mod/httpclient"
requestBuilder := httpclient.NewRequestBuilder(
httpclient.URL("https://url"),
httpclient.Method("GET"),
httpclient.Query("key", "value"),
httpclient.Header("key", "value"),
httpclient.BasicAuth("user", "pass"),
httpclient.Credential(*tlsconfig),
httpclient.Body(
httpclient.JSON(map[string]interface{}{
"a": "hello",
"b": true,
"c": 1,
}),
),
)
req, err := requestBuilder.Get()
````
### http.Response Processor
````go
//ResponseProcessor interface
type ResponseProcessor interface {
Process(context.Context, *http.Response) error
}
````
Implement your own ResponseProcessor
### http.Client Extension
extend the http.Client with more useful interfaces:
````go
import "github.com/x-mod/httpclient"
client := httpclient.New(
httpclient.MaxConnsPerHost(16),
httpclient.Retry(3),
httpclient.Response(
httpclient.NewDumpResponse(),
),
)
//get standard http.Client
c := client.GetClient()
//get standard http.Transport
tr := client.GetTransport()
//extension fn
err := client.Execute(context.TODO())
err := client.ExecuteRequest(context.TODO(), request)
````