Request
Send Request
These methods of Request
will fire the http request and return the response, MustXXX
will not return any error, panic if error occurs.
- Get(url string)
- Head(url string)
- Post(url string)
- Delete(url string)
- Patch(url string)
- Options(url string)
- Put(url string)
- MustGet(url string)
- MustHead(url string)
- MustPost(url string)
- MustDelete(url string)
- MustPatch(url string)
- MustOptions(url string)
- MustPut(url string)
- Send(method, url string) - Send request with given method name and url.
- Do(ctx …context.Context) - Send request with an optional context.
Request Settings
The following are the chainable settings of Request, all of which have corresponding global wrappers.
Basically, you can know the meaning of most settings directly from the method name.
URL Query and Path Parameter
- AddQueryParam(key, value string)
- SetQueryParam(key, value string)
- SetQueryParams(params map[string]string)
- SetQueryParamsAnyType(params map[string]interface{})
- SetQueryString(query string)
- SetPathParam(key, value string)
- SetPathParams(params map[string]string)
Header and Cookie
- SetHeader(key, value string)
- SetHeaders(hdrs map[string]string)
- SetHeaderOrder(keys …string)
- SetPseudoHeaderOrder(keys …string)
- SetBasicAuth(username, password string)
- SetBearerAuthToken(token string)
- SetDigestAuth(username, password string)
- SetContentType(contentType string)
- SetCookies(cookies …*http.Cookie)
Body and Marshal&Unmarshal
- SetBody(body interface{})
- SetBodyBytes(body []byte)
- SetBodyJsonBytes(body []byte)
- SetBodyJsonMarshal(v interface{})
- SetBodyJsonString(body string)
- SetBodyString(body string)
- SetBodyXmlBytes(body []byte)
- SetBodyXmlMarshal(v interface{})
- SetBodyXmlString(body string)
- SetSuccessResult(result interface{})
- SetErrorResult(error interface{})
Request Level Debug
- EnableTrace() - Disabled by default.
- DisableTrace()
- EnableDump()
- EnableDumpTo(output io.Writer)
- EnableDumpToFile(filename string)
- EnableDumpWithoutBody()
- EnableDumpWithoutHeader()
- EnableDumpWithoutRequest()
- EnableDumpWithoutRequestBody()
- EnableDumpWithoutResponse()
- EnableDumpWithoutResponseBody()
- SetDumpOptions(opt *DumpOptions)
Multipart & Form & Upload
- SetFormData(data map[string]string)
- SetFormDataAnyType(data map[string]interface{}) - syntax sugar for SetFormData
- SetFormDataFromValues(data url.Values)
- SetFile(paramName, filePath string)
- SetFiles(files map[string]string)
- SetFileBytes(paramName, filename string, content []byte)
- SetFileReader(paramName, filePath string, reader io.Reader)
- SetFileUpload(uploads …FileUpload) - Set the fully custimized multipart file upload options.
- SetUploadCallback(callback UploadCallback)
- SetUploadCallbackWithInterval(callback UploadCallback, minInterval time.Duration)
Download
- SetOutput(output io.Writer)
- SetOutputFile(file string)
- SetDownloadCallback(callback DownloadCallback)
- SetDownloadCallbackWithInterval(callback DownloadCallback, minInterval time.Duration)
Retry
- SetRetryCount(count int)
- SetRetryInterval(getRetryIntervalFunc GetRetryIntervalFunc)
- SetRetryFixedInterval(interval time.Duration)
- SetRetryBackoffInterval(min, max time.Duration)
- SetRetryHook(hook RetryHookFunc)
- AddRetryHook(hook RetryHookFunc)
- SetRetryCondition(condition RetryConditionFunc)
- AddRetryCondition(condition RetryConditionFunc)