在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:imroc/req开源软件地址:https://github.com/imroc/req开源编程语言:Go 97.8%开源软件介绍:
ReqSimple Go HTTP client with Black Magic (Less code and More efficiency). DocumentationFull documentation is available on the Req Official Website. Features
Get StartedInstall go get github.com/imroc/req/v3 Import import "github.com/imroc/req/v3" Basic Usage // For testing, you can create and send a request with the global wrapper methods
// that use the default client behind the scenes to initiate the request (you can
// just treat package name `req` as a Client or Request, no need to create any client
// or Request explicitly).
req.DevMode() // Use Client.DevMode to see all details, try and surprise :)
req.Get("https://httpbin.org/get") // Use Request.Get to send a GET request.
// In production, create a client explicitly and reuse it to send all requests
client := req.C(). // Use C() to create a client and set with chainable client settings.
SetUserAgent("my-custom-client").
SetTimeout(5 * time.Second).
DevMode()
resp, err := client.R(). // Use R() to create a request and set with chainable request settings.
SetHeader("Accept", "application/vnd.github.v3+json").
SetPathParam("username", "imroc").
SetQueryParam("page", "1").
SetResult(&result). // Unmarshal response into struct automatically if status code >= 200 and <= 299.
SetError(&errMsg). // Unmarshal response into struct automatically if status code >= 400.
EnableDump(). // Enable dump at request level to help troubleshoot, log content only when an unexpected exception occurs.
Get("https://api.github.com/users/{username}/repos")
if err != nil {
// Handle error.
// ...
return
}
if resp.IsSuccess() {
// Handle result.
// ...
return
}
if resp.IsError() {
// Handle errMsg.
// ...
return
}
// Handle unexpected response (corner case).
err = fmt.Errorf("got unexpected response, raw dump:\n%s", resp.Dump())
// ... Videos
More Check more introduction, tutorials, examples, best practices and API references on the official website. License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论