package
0.0.0-20240707130328-7cf8dae7750a
Repository: https://github.com/nite-coder/blackbear.git
Documentation: pkg.go.dev
# README
Request
A human readable and easy to use request package for Go
Features
- human readable and easy to use
- goroutine safe
- timeout support (default is 30 seconds)
- allow to set proxy
Usages
get request
resp, err := request.
GET("/v1/hello").
End()
if err != nil {
return nil, err
}
if resp.OK {
// if response's http status is between 200 ~ 299, then `resp.OK` should be ok
// when success, do something...
....
}
get request with header
resp, err := request.
GET("/v1/hello").
Header("Authorization", "token") // your token
End()
if err != nil {
return nil, err
}
if resp.OK {
// do something...
....
}
post request
form := url.Values{}
form.Add("grant_type", "password")
form.Add("client_id", "aaa")
form.Add("username", "bbb")
form.Add("password", "ccc")
body := form.Encode()
resp, err := request.
POST("/v1/hello").
Send(body).
End()
if err != nil {
return nil, err
}
if resp.OK {
// do something...
....
}
use proxy
resp, err := request.
GET("/v1/hello").
SetProxyURL("http://10.2.3.4:8080"). // use proxy here
End()
if err != nil {
return nil, err
}
if resp.OK {
// do something...
....
}
inspire by superAgent
# Functions
DELETE return RequestAgent that uses HTTP DELETE method with target URL.
GET return RequestAgent that uses HTTP GET method with target URL.
No description provided by the author
New create a new RequestAgent instance.
NewWithClient create a new RequestAgent instance with custom http client.
POST return RequestAgent that uses HTTP POST method with target URL.
PUT return RequestAgent that uses HTTP PUT method with target URL.
SetMethod return RequestAgent that uses HTTP method with target URL.
# Variables
ErrTimeout means http request have been timeout.