# README
httpclient
More smooth package for http operations as a client:
- http request builder
- http response processor
- http client extension
http.Request Builder
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
//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:
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)
# Functions
BasicAuth opt.
BearerAuth opt.
BearerAuthFunc opt.
Binary opt.
Content opt.
Cookie opt.
Debug opt.
DebugDialer debug dialer.
Dialer opt.
ExecuteRetry opt for client.Execute, only > 1.
Form opt.
Fragment opt.
Header opt.
Host opt [ip:port].
HTTPClient opt, when this option is SET, All above option will ignore.
JSON opt.
Keepalive opt.
MakeRequest make a http.Request.
MaxConnsPerHost opt.
MaxIdleConnsPerHost opt.
Method opt.
New client.
NewDumpResponse new.
NewRequestBuilder new.
Output of DumpResponse.
PB opt.
PBJSON opt.
Proxy opt.
Query opt.
Reader opt.
Retry opt for client.Do, only > 1.
Scheme opt.
URL opt.
Text opt.
Timeout opt.
TLSConfig for tls.
Transport opt, When this option is SET, Timeout/MaxConnsPerHost/MaxIdleConnsPerHost option will be IGNORED!!!.
URI opt.
URL opt.
User opt.
UserPassword opt.
XML opt.
# Variables
DefaultClientTimeout default client timeout for each do request.
DefaultMaxConnsPerHost default max connections for per host.
DefaultMaxIdleConnsPerHost default max idle connections for per host.
DefaultTLSConfig default tls.config is nil.
DefaultTLSHandhakeTimeout default client tls hands hake timeout.
# Structs
Body struct.
Client struct.
DumpResponse struct.
RequestBuilder struct.
# Interfaces
ResponseProcessor interface.
# Type aliases
BodyOpt type.
DialContext dialer function.
DumpResponseOpt option.
Opt for client.
ReqOpt opt.
ResponseProcessorFunc type.
No description provided by the author
No description provided by the author