Categorygithub.com/secr3t/req/v3
modulepackage
3.0.1
Repository: https://github.com/secr3t/req.git
Documentation: pkg.go.dev

# README

req

Simple Go HTTP client with Black Magic

Build Status Go Report Card License GitHub Releases Mentioned in Awesome Go

Documentation

Full documentation is available on the official website: https://req.cool.

Features

  • Simple and Powerful: Simple and easy to use, providing rich client-level and request-level settings, all of which are intuitive and chainable methods.
  • Easy Debugging: Powerful and convenient debug utilities, including debug logs, performance traces, and even dump the complete request and response content (see Debugging).
  • Easy API Testing: API testing can be done with minimal code, no need to explicitly create any Request or Client, or even to handle errors (See Quick HTTP Test)
  • Smart by Default: Detect and decode to utf-8 automatically if possible to avoid garbled characters (See Auto Decode), marshal request body and unmarshal response body automatically according to the Content-Type.
  • Support Multiple HTTP Versions: Support HTTP/1.1, HTTP/2, and HTTP/3, and can automatically detect the server side and select the optimal HTTP version for requests, you can also force the protocol if you want (See Force HTTP version).
  • Support Retry: Support automatic request retry and is fully customizable (See Retry).
  • Easy Download and Upload: You can download and upload files with simple request settings, and even set a callback to show real-time progress (See Download and Upload).
  • Exportable: req.Transport is exportable. Compared with http.Transport, it also supports HTTP3, dump content, middleware, etc. It can directly replace the Transport of http.Client in existing projects, and obtain more powerful functions with minimal code change.
  • Extensible: Support Middleware for Request, Response, Client and Transport (See Request and Response Middleware) and Client and Transport Middleware).

Get Started

Install

You first need Go installed (version 1.19+ is required), then you can use the below Go command to install req:

go get github.com/imroc/req/v3

Import

Import req to your code:

import "github.com/imroc/req/v3"

Basic Usage

# assume the following codes in main.go file
$ cat main.go
package main

import (
    "github.com/imroc/req/v3"
)

func main() {
    req.DevMode() // Treat the package name as a Client, enable development mode
    req.MustGet("https://httpbin.org/uuid") // Treat the package name as a Request, send GET request.

    req.EnableForceHTTP1() // Force using HTTP/1.1
    req.MustGet("https://httpbin.org/uuid")
}
$ go run main.go
2022/05/19 10:05:07.920113 DEBUG [req] HTTP/2 GET https://httpbin.org/uuid
:authority: httpbin.org
:method: GET
:path: /uuid
:scheme: https
user-agent: req/v3 (https://github.com/imroc/req/v3)
accept-encoding: gzip

:status: 200
date: Thu, 19 May 2022 02:05:08 GMT
content-type: application/json
content-length: 53
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

{
  "uuid": "bd519208-35d1-4483-ad9f-e1555ae108ba"
}

2022/05/19 10:05:09.340974 DEBUG [req] HTTP/1.1 GET https://httpbin.org/uuid
GET /uuid HTTP/1.1
Host: httpbin.org
User-Agent: req/v3 (https://github.com/imroc/req/v3)
Accept-Encoding: gzip

HTTP/1.1 200 OK
Date: Thu, 19 May 2022 02:05:09 GMT
Content-Type: application/json
Content-Length: 53
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "uuid": "49b7f916-c6f3-49d4-a6d4-22ae93b71969"
}

The sample code above is good for quick testing purposes, which use DevMode() to see request details, and send requests using global wrapper methods that use the default client behind the scenes to initiate the request.

In production, it is recommended to explicitly create a client, and then use the same client to send all requests, please see other examples below.

Videos

The following is a series of video tutorials for req:

More

Check more introduction, tutorials, examples, best practices and API references on the official website.

Simple GET

package main

import (
	"fmt"
	"github.com/imroc/req/v3"
	"log"
)

func main() {
	client := req.C() // Use C() to create a client.
	resp, err := client.R(). // Use R() to create a request.
		Get("https://httpbin.org/uuid")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resp)
}
{
  "uuid": "a4d4430d-0e5f-412f-88f5-722d84bc2a62"
}

Advanced GET

package main

import (
  "fmt"
  "github.com/imroc/req/v3"
  "log"
  "time"
)

type ErrorMessage struct {
  Message string `json:"message"`
}

type UserInfo struct {
  Name string `json:"name"`
  Blog string `json:"blog"`
}

func main() {
  client := req.C().
    SetUserAgent("my-custom-client"). // Chainable client settings.
    SetTimeout(5 * time.Second)

  var userInfo UserInfo
  var errMsg ErrorMessage
  resp, err := client.R().
    SetHeader("Accept", "application/vnd.github.v3+json"). // Chainable request settings.
    SetPathParam("username", "imroc"). // Replace path variable in url.
    SetSuccessResult(&userInfo). // Unmarshal response body into userInfo automatically if status code is between 200 and 299.
    SetErrorResult(&errMsg). // Unmarshal response body into errMsg automatically if status code >= 400.
    EnableDump(). // Enable dump at request level, only print dump content if there is an error or some unknown situation occurs to help troubleshoot.
    Get("https://api.github.com/users/{username}")

  if err != nil { // Error handling.
    log.Println("error:", err)
    log.Println("raw content:")
    log.Println(resp.Dump()) // Record raw content when error occurs.
    return
  }

  if resp.IsErrorState() { // Status code >= 400.
    fmt.Println(errMsg.Message) // Record error message returned.
    return
  }

  if resp.IsSuccessState() { // Status code is between 200 and 299.
    fmt.Printf("%s (%s)\n", userInfo.Name, userInfo.Blog)
    return
  }

  // Unknown status code.
  log.Println("unknown status", resp.Status)
  log.Println("raw content:")
  log.Println(resp.Dump()) // Record raw content when server returned unknown status code.
}

Normally it will output (SuccessState):

roc (https://imroc.cc)

More Advanced GET

You can set up a unified logic for error handling on the client, so that each time you send a request you only need to focus on the success situation, reducing duplicate code.

package main

import (
	"fmt"
	"github.com/imroc/req/v3"
	"log"
	"time"
)

type ErrorMessage struct {
	Message string `json:"message"`
}

func (msg *ErrorMessage) Error() string {
	return fmt.Sprintf("API Error: %s", msg.Message)
}

type UserInfo struct {
	Name string `json:"name"`
	Blog string `json:"blog"`
}

var client = req.C().
	SetUserAgent("my-custom-client"). // Chainable client settings.
	SetTimeout(5 * time.Second).
	EnableDumpEachRequest().
	SetCommonErrorResult(&ErrorMessage{}).
	OnAfterResponse(func(client *req.Client, resp *req.Response) error {
		if resp.Err != nil { // There is an underlying error, e.g. network error or unmarshal error.
			return nil
		}
		if errMsg, ok := resp.ErrorResult().(*ErrorMessage); ok {
			resp.Err = errMsg // Convert api error into go error
			return nil
		}
		if !resp.IsSuccessState() {
			// Neither a success response nor a error response, record details to help troubleshooting
			resp.Err = fmt.Errorf("bad status: %s\nraw content:\n%s", resp.Status, resp.Dump())
		}
		return nil
	})

func main() {
	var userInfo UserInfo
	resp, err := client.R().
		SetHeader("Accept", "application/vnd.github.v3+json"). // Chainable request settings
		SetPathParam("username", "imroc").
		SetSuccessResult(&userInfo). // Unmarshal response body into userInfo automatically if status code is between 200 and 299.
		Get("https://api.github.com/users/{username}")

	if err != nil { // Error handling.
		log.Println("error:", err)
		return
	}

	if resp.IsSuccessState() { // Status code is between 200 and 299.
		fmt.Printf("%s (%s)\n", userInfo.Name, userInfo.Blog)
	}
}

Simple POST

package main

import (
  "fmt"
  "github.com/imroc/req/v3"
  "log"
)

type Repo struct {
  Name string `json:"name"`
  Url  string `json:"url"`
}

type Result struct {
  Data string `json:"data"`
}

func main() {
  client := req.C().DevMode()
  var result Result

  resp, err := client.R().
    SetBody(&Repo{Name: "req", Url: "https://github.com/imroc/req"}).
    SetSuccessResult(&result).
    Post("https://httpbin.org/post")
  if err != nil {
    log.Fatal(err)
  }

  if !resp.IsSuccessState() {
    fmt.Println("bad response status:", resp.Status)
    return
  }
  fmt.Println("++++++++++++++++++++++++++++++++++++++++++++++++")
  fmt.Println("data:", result.Data)
  fmt.Println("++++++++++++++++++++++++++++++++++++++++++++++++")
}
2022/05/19 20:11:00.151171 DEBUG [req] HTTP/2 POST https://httpbin.org/post
:authority: httpbin.org
:method: POST
:path: /post
:scheme: https
user-agent: req/v3 (https://github.com/imroc/req/v3)
content-type: application/json; charset=utf-8
content-length: 55
accept-encoding: gzip

{"name":"req","website":"https://github.com/imroc/req"}

:status: 200
date: Thu, 19 May 2022 12:11:00 GMT
content-type: application/json
content-length: 651
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

{
  "args": {},
  "data": "{\"name\":\"req\",\"website\":\"https://github.com/imroc/req\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Content-Length": "55",
    "Content-Type": "application/json; charset=utf-8",
    "Host": "httpbin.org",
    "User-Agent": "req/v3 (https://github.com/imroc/req/v3)",
    "X-Amzn-Trace-Id": "Root=1-628633d4-7559d633152b4307288ead2e"
  },
  "json": {
    "name": "req",
    "website": "https://github.com/imroc/req"
  },
  "origin": "103.7.29.30",
  "url": "https://httpbin.org/post"
}

++++++++++++++++++++++++++++++++++++++++++++++++
data: {"name":"req","url":"https://github.com/imroc/req"}
++++++++++++++++++++++++++++++++++++++++++++++++

Do API Style

If you like, you can also use a Do API style like the following to make requests:

package main

import (
	"fmt"
	"github.com/imroc/req/v3"
)

type APIResponse struct {
	Origin string `json:"origin"`
	Url    string `json:"url"`
}

func main() {
	var resp APIResponse
	c := req.C().SetBaseURL("https://httpbin.org/post")
	err := c.Post().
		SetBody("hello").
		Do().
		Into(&resp)
	if err != nil {
		panic(err)
	}
	fmt.Println("My IP is", resp.Origin)
}
My IP is 182.138.155.113
  • The order of chain calls is more intuitive: first call Client to create a request with a specified Method, then use chain calls to set the request, then use Do() to fire the request, return Response, and finally call Response.Into to unmarshal response body into specified object.
  • Response.Into will return an error if an error occurs during sending the request or during unmarshalling.
  • The url of some APIs is fixed, and different types of requests are implemented by passing different bodies. In this scenario, Client.SetBaseURL can be used to set a unified url, and there is no need to set the url for each request when initiating a request. Of course, you can also call Request.SetURL to set it if you need it.

Build SDK With Req

Here is an example of building GitHub's SDK with req, using two styles (GetUserProfile_Style1, GetUserProfile_Style2).

import (
	"context"
	"fmt"
	"github.com/imroc/req/v3"
)

type ErrorMessage struct {
	Message string `json:"message"`
}

// Error implements go error interface.
func (msg *ErrorMessage) Error() string {
	return fmt.Sprintf("API Error: %s", msg.Message)
}

type GithubClient struct {
	*req.Client
}

func NewGithubClient() *GithubClient {
	return &GithubClient{
		Client: req.C().
			SetBaseURL("https://api.github.com").
			SetCommonErrorResult(&ErrorMessage{}).
			EnableDumpEachRequest().
			OnAfterResponse(func(client *req.Client, resp *req.Response) error {
				if resp.Err != nil { // There is an underlying error, e.g. network error or unmarshal error.
					return nil
				}
				if errMsg, ok := resp.ErrorResult().(*ErrorMessage); ok {
					resp.Err = errMsg // Convert api error into go error
					return nil
				}
				if !resp.IsSuccessState() {
					// Neither a success response nor a error response, record details to help troubleshooting
					resp.Err = fmt.Errorf("bad status: %s\nraw content:\n%s", resp.Status, resp.Dump())
				}
				return nil
			}),
	}
}

type UserProfile struct {
	Name string `json:"name"`
	Blog string `json:"blog"`
}

// GetUserProfile_Style1 returns the user profile for the specified user.
// Github API doc: https://docs.github.com/en/rest/users/users#get-a-user
func (c *GithubClient) GetUserProfile_Style1(ctx context.Context, username string) (user *UserProfile, err error) {
	_, err = c.R().
		SetContext(ctx).
		SetPathParam("username", username).
		SetSuccessResult(&user).
		Get("/users/{username}")
	return
}

// GetUserProfile_Style2 returns the user profile for the specified user.
// Github API doc: https://docs.github.com/en/rest/users/users#get-a-user
func (c *GithubClient) GetUserProfile_Style2(ctx context.Context, username string) (user *UserProfile, err error) {
	err = c.Get("/users/{username}").
		SetPathParam("username", username).
		Do(ctx).
		Into(&user)
	return
}

Contributing

If you have a bug report or feature request, you can open an issue, and pull requests are also welcome.

Contact

If you have questions, feel free to reach out to us in the following ways:

Sponsors

If you like req and it really helps you, feel free to reward me with a cup of coffee, and don't forget to mention your github id.


Wechat

Alipay

Many thanks to the following sponsors:


M-Cosmosss πŸ₯‡

aadog πŸ₯ˆ

License

Req released under MIT license, refer LICENSE file.

# Packages

No description provided by the author

# Functions

AddCommonQueryParam is a global wrapper methods which delegated to the default client's AddCommonQueryParam.
AddCommonQueryParams is a global wrapper methods which delegated to the default client's AddCommonQueryParams.
AddCommonRetryCondition is a global wrapper methods which delegated to the default client, create a request and AddCommonRetryCondition for request.
AddCommonRetryHook is a global wrapper methods which delegated to the default client, create a request and AddCommonRetryHook for request.
AddQueryParam is a global wrapper methods which delegated to the default client, create a request and AddQueryParam for request.
AddQueryParams is a global wrapper methods which delegated to the default client, create a request and AddQueryParams for request.
AddRetryCondition is a global wrapper methods which delegated to the default client, create a request and AddRetryCondition for request.
AddRetryHook is a global wrapper methods which delegated to the default client, create a request and AddRetryHook for request.
AllowedDomainRedirectPolicy allows redirect only if the redirected domain match one of the domain that specified.
AllowedHostRedirectPolicy allows redirect only if the redirected host match one of the host that specified.
AlwaysCopyHeaderRedirectPolicy ensures that the given sensitive headers will always be copied on redirect.
C create a new client.
ClearCookies is a global wrapper methods which delegated to the default client's ClearCookies.
DefaultClient returns the global default Client.
Delete is a global wrapper methods which delegated to the default client, create a request and Delete for request.
DevMode is a global wrapper methods which delegated to the default client's DevMode.
DisableAllowGetMethodPayload is a global wrapper methods which delegated to the default client's DisableAllowGetMethodPayload.
DisableAutoDecode is a global wrapper methods which delegated to the default client's DisableAutoDecode.
DisableAutoReadResponse is a global wrapper methods which delegated to the default client's DisableAutoReadResponse.
DisableCompression is a global wrapper methods which delegated to the default client's DisableCompression.
DisableDebugLog is a global wrapper methods which delegated to the default client's DisableDebugLog.
DisableDumpAll is a global wrapper methods which delegated to the default client's DisableDumpAll.
DisableForceChunkedEncoding is a global wrapper methods which delegated to the default client, create a request and DisableForceChunkedEncoding for request.
DisableForceHttpVersion is a global wrapper methods which delegated to the default client's DisableForceHttpVersion.
DisableForceMultipart is a global wrapper methods which delegated to the default client, create a request and DisableForceMultipart for request.
DisableH2C is a global wrapper methods which delegated to the default client's DisableH2C.
DisableInsecureSkipVerify is a global wrapper methods which delegated to the default client's DisableInsecureSkipVerify.
DisableKeepAlives is a global wrapper methods which delegated to the default client's DisableKeepAlives.
DisableTrace is a global wrapper methods which delegated to the default client, create a request and DisableTrace for request.
DisableTraceAll is a global wrapper methods which delegated to the default client's DisableTraceAll.
EnableAllowGetMethodPayload is a global wrapper methods which delegated to the default client's EnableAllowGetMethodPayload.
EnableAutoDecode is a global wrapper methods which delegated to the default client's EnableAutoDecode.
EnableAutoReadResponse is a global wrapper methods which delegated to the default client's EnableAutoReadResponse.
EnableCloseConnection is a global wrapper methods which delegated to the default client, create a request and EnableCloseConnection for request.
EnableCompression is a global wrapper methods which delegated to the default client's EnableCompression.
EnableDebugLog is a global wrapper methods which delegated to the default client's EnableDebugLog.
EnableDump is a global wrapper methods which delegated to the default client, create a request and EnableDump for request.
EnableDumpAll is a global wrapper methods which delegated to the default client's EnableDumpAll.
EnableDumpAllAsync is a global wrapper methods which delegated to the default client's EnableDumpAllAsync.
EnableDumpAllTo is a global wrapper methods which delegated to the default client's EnableDumpAllTo.
EnableDumpAllToFile is a global wrapper methods which delegated to the default client's EnableDumpAllToFile.
EnableDumpAllWithoutBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutBody.
EnableDumpAllWithoutHeader is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutHeader.
EnableDumpAllWithoutRequest is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutRequest.
EnableDumpAllWithoutRequestBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutRequestBody.
EnableDumpAllWithoutResponse is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutResponse.
EnableDumpAllWithoutResponseBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutResponseBody.
EnableDumpEachRequest is a global wrapper methods which delegated to the default client's EnableDumpEachRequest.
EnableDumpEachRequestWithoutBody is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutBody.
EnableDumpEachRequestWithoutHeader is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutHeader.
EnableDumpEachRequestWithoutRequest is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutRequest.
EnableDumpEachRequestWithoutRequestBody is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutRequestBody.
EnableDumpEachRequestWithoutResponse is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutResponse.
EnableDumpEachRequestWithoutResponseBody is a global wrapper methods which delegated to the default client's EnableDumpEachRequestWithoutResponseBody.
EnableDumpTo is a global wrapper methods which delegated to the default client, create a request and EnableDumpTo for request.
EnableDumpToFile is a global wrapper methods which delegated to the default client, create a request and EnableDumpToFile for request.
EnableDumpWithoutBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutBody for request.
EnableDumpWithoutHeader is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutHeader for request.
EnableDumpWithoutRequest is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutRequest for request.
EnableDumpWithoutRequestBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutRequestBody for request.
EnableDumpWithoutResponse is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutResponse for request.
EnableDumpWithoutResponseBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutResponseBody for request.
EnableForceChunkedEncoding is a global wrapper methods which delegated to the default client, create a request and EnableForceChunkedEncoding for request.
EnableForceHTTP1 is a global wrapper methods which delegated to the default client's EnableForceHTTP1.
EnableForceHTTP2 is a global wrapper methods which delegated to the default client's EnableForceHTTP2.
EnableForceHTTP3 is a global wrapper methods which delegated to the default client's EnableForceHTTP3.
EnableForceMultipart is a global wrapper methods which delegated to the default client, create a request and EnableForceMultipart for request.
EnableH2C is a global wrapper methods which delegated to the default client's EnableH2C.
EnableHTTP3 is a global wrapper methods which delegated to the default client's EnableHTTP3.
EnableInsecureSkipVerify is a global wrapper methods which delegated to the default client's EnableInsecureSkipVerify.
EnableKeepAlives is a global wrapper methods which delegated to the default client's EnableKeepAlives.
EnableTrace is a global wrapper methods which delegated to the default client, create a request and EnableTrace for request.
EnableTraceAll is a global wrapper methods which delegated to the default client's EnableTraceAll.
Get is a global wrapper methods which delegated to the default client, create a request and Get for request.
GetClient is a global wrapper methods which delegated to the default client's GetClient.
GetTLSClientConfig is a global wrapper methods which delegated to the default client's GetTLSClientConfig.
Head is a global wrapper methods which delegated to the default client, create a request and Head for request.
MaxRedirectPolicy specifies the max number of redirect.
MustDelete is a global wrapper methods which delegated to the default client, create a request and MustDelete for request.
MustGet is a global wrapper methods which delegated to the default client, create a request and MustGet for request.
MustHead is a global wrapper methods which delegated to the default client, create a request and MustHead for request.
MustOptions is a global wrapper methods which delegated to the default client, create a request and MustOptions for request.
MustPatch is a global wrapper methods which delegated to the default client, create a request and MustPatch for request.
MustPost is a global wrapper methods which delegated to the default client, create a request and Get for request.
MustPut is a global wrapper methods which delegated to the default client, create a request and MustPut for request.
NewClient is the alias of C.
NewLogger create a Logger wraps the *log.Logger.
NewRequest is a global wrapper methods which delegated to the default client's NewRequest.
NewTransport is an alias of T.
NoRedirectPolicy disable redirect behaviour.
OnAfterResponse is a global wrapper methods which delegated to the default client's OnAfterResponse.
OnBeforeRequest is a global wrapper methods which delegated to the default client's OnBeforeRequest.
Options is a global wrapper methods which delegated to the default client, create a request and Options for request.
Patch is a global wrapper methods which delegated to the default client, create a request and Patch for request.
Post
Post is a global wrapper methods which delegated to the default client, create a request and Post for request.
Put is a global wrapper methods which delegated to the default client, create a request and Put for request.
R is a global wrapper methods which delegated to the default client's R().
SameDomainRedirectPolicy allows redirect only if the redirected domain is the same as original domain, e.g.
SameHostRedirectPolicy allows redirect only if the redirected host is the same as original host, e.g.
SetAutoDecodeAllContentType is a global wrapper methods which delegated to the default client's SetAutoDecodeAllContentType.
SetAutoDecodeContentType is a global wrapper methods which delegated to the default client's SetAutoDecodeContentType.
SetAutoDecodeContentTypeFunc is a global wrapper methods which delegated to the default client's SetAutoDecodeAllTypeFunc.
SetBaseURL is a global wrapper methods which delegated to the default client's SetBaseURL.
SetBasicAuth is a global wrapper methods which delegated to the default client, create a request and SetBasicAuth for request.
SetBearerAuthToken is a global wrapper methods which delegated to the default client, create a request and SetBearerAuthToken for request.
SetBody is a global wrapper methods which delegated to the default client, create a request and SetBody for request.
SetBodyBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyBytes for request.
SetBodyJsonBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonBytes for request.
SetBodyJsonMarshal is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonMarshal for request.
SetBodyJsonString is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonString for request.
SetBodyString is a global wrapper methods which delegated to the default client, create a request and SetBodyString for request.
SetBodyXmlBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlBytes for request.
SetBodyXmlMarshal is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlMarshal for request.
SetBodyXmlString is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlString for request.
SetCertFromFile is a global wrapper methods which delegated to the default client's SetCertFromFile.
SetCerts is a global wrapper methods which delegated to the default client's SetCerts.
SetCommonBasicAuth is a global wrapper methods which delegated to the default client's SetCommonBasicAuth.
SetCommonBearerAuthToken is a global wrapper methods which delegated to the default client's SetCommonBearerAuthToken.
SetCommonContentType is a global wrapper methods which delegated to the default client's SetCommonContentType.
SetCommonCookies is a global wrapper methods which delegated to the default client's SetCommonCookies.
SetCommonDumpOptions is a global wrapper methods which delegated to the default client's SetCommonDumpOptions.
SetCommonError is a global wrapper methods which delegated to the default client's SetCommonErrorResult.
SetCommonErrorResult is a global wrapper methods which delegated to the default client's SetCommonError.
SetCommonFormData is a global wrapper methods which delegated to the default client's SetCommonFormData.
SetCommonFormDataFromValues is a global wrapper methods which delegated to the default client's SetCommonFormDataFromValues.
SetCommonHeader is a global wrapper methods which delegated to the default client's SetCommonHeader.
SetCommonHeaders is a global wrapper methods which delegated to the default client's SetCommonHeaders.
SetCommonPathParam is a global wrapper methods which delegated to the default client's SetCommonPathParam.
SetCommonPathParams is a global wrapper methods which delegated to the default client's SetCommonPathParams.
SetCommonQueryParam is a global wrapper methods which delegated to the default client's SetCommonQueryParam.
SetCommonQueryParams is a global wrapper methods which delegated to the default client's SetCommonQueryParams.
SetCommonQueryString is a global wrapper methods which delegated to the default client's SetCommonQueryString.
SetCommonRetryBackoffInterval is a global wrapper methods which delegated to the default client, create a request and SetCommonRetryBackoffInterval for request.
SetCommonRetryCondition is a global wrapper methods which delegated to the default client, create a request and SetCommonRetryCondition for request.
SetCommonRetryCount is a global wrapper methods which delegated to the default client, create a request and SetCommonRetryCount for request.
SetCommonRetryFixedInterval is a global wrapper methods which delegated to the default client, create a request and SetCommonRetryFixedInterval for request.
SetCommonRetryHook is a global wrapper methods which delegated to the default client, create a request and SetRetryHook for request.
SetCommonRetryInterval is a global wrapper methods which delegated to the default client, create a request and SetCommonRetryInterval for request.
SetContentType is a global wrapper methods which delegated to the default client, create a request and SetContentType for request.
SetContext is a global wrapper methods which delegated to the default client, create a request and SetContext for request.
SetCookieJar is a global wrapper methods which delegated to the default client's SetCookieJar.
SetCookies is a global wrapper methods which delegated to the default client, create a request and SetCookies for request.
SetDefaultClient override the global default Client.
SetDial is a global wrapper methods which delegated to the default client's SetDial.
SetDialTLS is a global wrapper methods which delegated to the default client's SetDialTLS.
SetDownloadCallback is a global wrapper methods which delegated to the default client, create a request and SetDownloadCallback for request.
SetDownloadCallbackWithInterval is a global wrapper methods which delegated to the default client, create a request and SetDownloadCallbackWithInterval for request.
SetDumpOptions is a global wrapper methods which delegated to the default client, create a request and SetDumpOptions for request.
SetError is a global wrapper methods which delegated to the default client, create a request and SetErrorResult for request.
SetErrorResult is a global wrapper methods which delegated to the default client, create a request and SetErrorResult for request.
SetFile is a global wrapper methods which delegated to the default client, create a request and SetFile for request.
SetFileBytes is a global wrapper methods which delegated to the default client, create a request and SetFileBytes for request.
SetFileReader is a global wrapper methods which delegated to the default client, create a request and SetFileReader for request.
SetFiles is a global wrapper methods which delegated to the default client, create a request and SetFiles for request.
SetFileUpload is a global wrapper methods which delegated to the default client, create a request and SetFileUpload for request.
SetFormData is a global wrapper methods which delegated to the default client, create a request and SetFormData for request.
SetFormDataAnyType is a global wrapper methods which delegated to the default client, create a request and SetFormDataAnyType for request.
SetFormDataFromValues is a global wrapper methods which delegated to the default client, create a request and SetFormDataFromValues for request.
SetHeader is a global wrapper methods which delegated to the default client, create a request and SetHeader for request.
SetHeaders is a global wrapper methods which delegated to the default client, create a request and SetHeaders for request.
SetJsonMarshal is a global wrapper methods which delegated to the default client's SetJsonMarshal.
SetJsonUnmarshal is a global wrapper methods which delegated to the default client's SetJsonUnmarshal.
SetLogger is a global wrapper methods which delegated to the default client's SetLogger.
SetOutput is a global wrapper methods which delegated to the default client, create a request and SetOutput for request.
SetOutputDirectory is a global wrapper methods which delegated to the default client's SetOutputDirectory.
SetOutputFile is a global wrapper methods which delegated to the default client, create a request and SetOutputFile for request.
SetPathParam is a global wrapper methods which delegated to the default client, create a request and SetPathParam for request.
SetPathParams is a global wrapper methods which delegated to the default client, create a request and SetPathParams for request.
SetProxy is a global wrapper methods which delegated to the default client's SetProxy.
SetProxyURL is a global wrapper methods which delegated to the default client's SetProxyURL.
SetQueryParam is a global wrapper methods which delegated to the default client, create a request and SetQueryParam for request.
SetQueryParams is a global wrapper methods which delegated to the default client, create a request and SetQueryParams for request.
SetQueryParamsAnyType is a global wrapper methods which delegated to the default client, create a request and SetQueryParamsAnyType for request.
SetQueryString is a global wrapper methods which delegated to the default client, create a request and SetQueryString for request.
SetRedirectPolicy is a global wrapper methods which delegated to the default client's SetRedirectPolicy.
SetResponseBodyTransformer is a global wrapper methods which delegated to the default client, create a request and SetResponseBodyTransformer for request.
SetResult is a global wrapper methods which delegated to the default client, create a request and SetSuccessResult for request.
SetResultStateCheckFunc is a global wrapper methods which delegated to the default client's SetCommonResultStateCheckFunc.
SetRetryBackoffInterval is a global wrapper methods which delegated to the default client, create a request and SetRetryBackoffInterval for request.
SetRetryCondition is a global wrapper methods which delegated to the default client, create a request and SetRetryCondition for request.
SetRetryCount is a global wrapper methods which delegated to the default client, create a request and SetRetryCount for request.
SetRetryFixedInterval is a global wrapper methods which delegated to the default client, create a request and SetRetryFixedInterval for request.
SetRetryHook is a global wrapper methods which delegated to the default client, create a request and SetRetryHook for request.
SetRetryInterval is a global wrapper methods which delegated to the default client, create a request and SetRetryInterval for request.
SetRootCertFromString is a global wrapper methods which delegated to the default client's SetRootCertFromString.
SetRootCertsFromFile is a global wrapper methods which delegated to the default client's SetRootCertsFromFile.
SetScheme is a global wrapper methods which delegated to the default client's SetScheme.
SetSuccessResult is a global wrapper methods which delegated to the default client, create a request and SetSuccessResult for request.
SetTimeout is a global wrapper methods which delegated to the default client's SetTimeout.
SetTLSClientConfig is a global wrapper methods which delegated to the default client's SetTLSClientConfig.
SetTLSHandshakeTimeout is a global wrapper methods which delegated to the default client's SetTLSHandshakeTimeout.
SetUnixSocket is a global wrapper methods which delegated to the default client, create a request and SetUnixSocket for request.
SetUploadCallback is a global wrapper methods which delegated to the default client, create a request and SetUploadCallback for request.
SetUploadCallbackWithInterval is a global wrapper methods which delegated to the default client, create a request and SetUploadCallbackWithInterval for request.
SetURL is a global wrapper methods which delegated to the default client, create a request and SetURL for request.
SetUserAgent is a global wrapper methods which delegated to the default client's SetUserAgent.
SetXmlMarshal is a global wrapper methods which delegated to the default client's SetXmlMarshal.
SetXmlUnmarshal is a global wrapper methods which delegated to the default client's SetXmlUnmarshal.
T create a Transport.
WrapRoundTrip is a global wrapper methods which delegated to the default client's WrapRoundTrip.
WrapRoundTripFunc is a global wrapper methods which delegated to the default client's WrapRoundTripFunc.

# Constants

ErrorState indicates the response is in error state, and result will be unmarshalled if Request.SetErrorResult or Client.SetCommonErrorResult is called.
SuccessState indicates the response is in success state, and result will be unmarshalled if Request.SetSuccessResult is called.
UnknownState indicates the response is in unknown state, and handler will be invoked if Request.SetUnknownResultHandlerFunc or Client.SetCommonUnknownResultHandlerFunc is called.

# Variables

NoBody is an io.ReadCloser with no bytes.

# Structs

Client is the req's http client.
ContentDisposition represents parameters in `Content-Disposition` MIME header of multipart request.
DownloadInfo is the information for each DownloadCallback call.
DumpOptions controls the dump behavior.
FileUpload represents a "form-data" multipart.
No description provided by the author
Request struct is used to compose and fire individual request from req client.
Response is the http response.
TraceInfo represents the trace information.
Transport is an implementation of http.RoundTripper that supports HTTP, HTTPS, and HTTP proxies (for either HTTP or HTTPS with CONNECT).
UploadInfo is the information for each UploadCallback call.

# Interfaces

Logger is the abstract logging interface, gives control to the Req users, choice of the logger.
RoundTripper is the interface of req's Client.

# Type aliases

DownloadCallback is the callback which will be invoked during response body download.
No description provided by the author
GetRetryIntervalFunc is a function that determines how long should sleep between retry attempts.
HttpRoundTripFunc is a http.RoundTripper implementation, which is a simple function.
HttpRoundTripWrapper is transport middleware function.
HttpRoundTripWrapperFunc is transport middleware function, more convenient than HttpRoundTripWrapper.
RedirectPolicy represents the redirect policy for Client.
No description provided by the author
No description provided by the author
ResultState represents the state of the result.
RetryConditionFunc is a retry condition, which determines whether the request should retry.
RetryHookFunc is a retry hook which will be executed before a retry.
RoundTripFunc is a RoundTripper implementation, which is a simple function.
RoundTripWrapper is client middleware function.
RoundTripWrapperFunc is client middleware function, more convenient than RoundTripWrapper.
UploadCallback is the callback which will be invoked during multipart upload.