Documentation
¶
Index ¶
- Constants
- func DetectContentType(body interface{}) string
- func IsJSONType(ct string) bool
- func IsProtobufType(ct string) bool
- func IsStringEmpty(str string) bool
- func IsXMLType(ct string) bool
- func IsYAMLType(ct string) bool
- func Unmarshalc(c *Client, ct string, b []byte, d interface{}) (err error)
- type Builder
- func (builder *Builder) AddHeader(key, value string) *Builder
- func (builder *Builder) AddHeaders(headers map[string]string) *Builder
- func (builder *Builder) Body(body io.Reader) *Builder
- func (builder *Builder) Build() (*Request, *Response)
- func (builder *Builder) CONNECT() *Builder
- func (builder *Builder) Client(cli *Client) *Builder
- func (builder *Builder) ContentType(contentType string) *Builder
- func (builder *Builder) Context(ctx context.Context) *Builder
- func (builder *Builder) DELETE() *Builder
- func (builder *Builder) EnableJSONEscapeHTML(enabled bool) *Builder
- func (builder *Builder) ErrorResult(result interface{}) *Builder
- func (builder *Builder) File(paramName ParamName, filePath FilePath) *Builder
- func (builder *Builder) FileReader(paramName ParamName, fileName Filename, reader io.Reader) *Builder
- func (builder *Builder) GET() *Builder
- func (builder *Builder) HEAD() *Builder
- func (builder *Builder) Header(header http.Header) *Builder
- func (builder *Builder) MultipartField(param ParamName, fileName Filename, contentType string, reader io.Reader) *Builder
- func (builder *Builder) MultipartFormData(data map[ParamName]io.Reader) *Builder
- func (builder *Builder) OPTIONS() *Builder
- func (builder *Builder) PATCH() *Builder
- func (builder *Builder) POST() *Builder
- func (builder *Builder) PUT() *Builder
- func (builder *Builder) PathParam(param, value string) *Builder
- func (builder *Builder) PathParams(params map[string]string) *Builder
- func (builder *Builder) QueryParam(param, value string) *Builder
- func (builder *Builder) QueryParams(params map[string]string) *Builder
- func (builder *Builder) Result(result interface{}) *Builder
- func (builder *Builder) SetFiles(files map[ParamName]FilePath) *Builder
- func (builder *Builder) SetHeader(key, value string) *Builder
- func (builder *Builder) SetHeaders(headers map[string]string) *Builder
- func (builder *Builder) SetMultipartFields(fields ...*MultipartField) *Builder
- func (builder *Builder) TRACE() *Builder
- func (builder *Builder) URL(url string) *Builder
- type Client
- func (cli *Client) Execute(req *Request, resp *Response) (err error)
- func (c *Client) GetClient() *http.Client
- func (c *Client) IsProxySet() bool
- func (cli *Client) RawClient() *http.Client
- func (c *Client) RemoveProxy() (*Client, error)
- func (c *Client) SetCertificates(certs ...tls.Certificate) (*Client, error)
- func (c *Client) SetRootCertificate(pemFilePath string) (*Client, error)
- func (c *Client) SetRootCertificateFromString(pemContent string) (*Client, error)
- type Doer
- type File
- type FilePath
- type Filename
- type Interceptor
- type MultipartField
- type Option
- func AddHeader(key, value string) Option
- func AddHeaders(headers map[string]string) Option
- func AuthScheme(scheme string) Option
- func AuthToken(token string) Option
- func BasicAuth(username, password string) Option
- func ChainInterceptor(interceptors ...Interceptor) Option
- func CheckRedirect(policies ...RedirectPolicy) Option
- func Cookie(hc *http.Cookie) Option
- func CookieJar(jar http.CookieJar) Option
- func Cookies(cs []*http.Cookie) Option
- func DoNotParseResponse(parse bool) Option
- func EnableCloseConnection(enabled bool) Option
- func EnableJSONEscapeHTML(enabled bool) Option
- func FormData(data map[string]string) Option
- func Header(header http.Header) Option
- func HostURL(url string) Option
- func PathParam(param, value string) Option
- func PathParams(params map[string]string) Option
- func Proxy(proxyURL string) Option
- func QueryParam(param, value string) Option
- func QueryParams(params map[string]string) Option
- func Scheme(scheme string) Option
- func SetHeader(key, value string) Option
- func SetHeaders(headers map[string]string) Option
- func SetOutputDirectory(dirPath string) Option
- func TLSConfig(config *tls.Config) Option
- func Timeout(timeout time.Duration) Option
- func Transport(transport http.RoundTripper) Option
- type ParamName
- type RedirectPolicy
- type RedirectPolicyFunc
- type Request
- func (r *Request) Body() interface{}
- func (r *Request) ContentType() string
- func (r *Request) Ctx() context.Context
- func (r *Request) Err() error
- func (r *Request) Header() http.Header
- func (r *Request) Method() string
- func (r *Request) RawRequest() *http.Request
- func (r *Request) Url() string
- func (r *Request) WithRawRequest(req *http.Request) *Request
- type Response
- type User
Constants ¶
const ( MIMEJSON = "application/json" MIMEHTML = "text/html" MIMEXML = "application/xml" MIMEXML2 = "text/xml" MIMEPlain = "text/plain" MIMEPOSTForm = "application/x-www-form-urlencoded" MIMEMultipartPOSTForm = "multipart/form-data" MIMEPROTOBUF = "application/x-protobuf" MIMEMSGPACK = "application/x-msgpack" MIMEMSGPACK2 = "application/msgpack" MIMEYAML = "application/x-yaml" )
Content-Type MIME of the most common data formats.
Variables ¶
This section is empty.
Functions ¶
func DetectContentType ¶ added in v1.12.1
func DetectContentType(body interface{}) string
DetectContentType method is used to figure out `Request.Body` content type for request header
func IsJSONType ¶ added in v1.12.1
IsJSONType method is to check JSON content type or not
func IsProtobufType ¶ added in v1.12.1
IsProtobufType method is to check Protocol Buffers content type or not
func IsStringEmpty ¶ added in v1.12.1
IsStringEmpty method tells whether given string is empty or not
func IsYAMLType ¶ added in v1.12.1
IsYAMLType method is to check YAML content type or not
Types ¶
type Builder ¶ added in v1.12.1
type Builder struct { Request *Request Response *Response // contains filtered or unexported fields }
func NewBuilder ¶ added in v1.12.1
func (*Builder) AddHeaders ¶ added in v1.12.1
func (*Builder) ContentType ¶ added in v1.12.1
func (*Builder) EnableJSONEscapeHTML ¶ added in v1.12.1
func (*Builder) ErrorResult ¶ added in v1.12.1
func (*Builder) FileReader ¶ added in v1.12.1
func (*Builder) MultipartField ¶ added in v1.12.1
func (*Builder) MultipartFormData ¶ added in v1.12.1
func (*Builder) PathParams ¶ added in v1.12.1
func (*Builder) QueryParam ¶ added in v1.12.1
func (*Builder) QueryParams ¶ added in v1.12.1
func (*Builder) SetHeaders ¶ added in v1.12.1
func (*Builder) SetMultipartFields ¶ added in v1.12.1
func (builder *Builder) SetMultipartFields(fields ...*MultipartField) *Builder
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GetClient ¶ added in v1.12.1
GetClient method returns the current `http.Client` used by the client.
func (*Client) IsProxySet ¶ added in v1.12.1
IsProxySet method returns the true is proxy is set from resty client otherwise false. By default proxy is set from environment, refer to `http.ProxyFromEnvironment`.
func (*Client) RemoveProxy ¶ added in v1.12.1
RemoveProxy method removes the proxy configuration from Resty client
client.RemoveProxy()
func (*Client) SetCertificates ¶ added in v1.12.1
func (c *Client) SetCertificates(certs ...tls.Certificate) (*Client, error)
SetCertificates method helps to set client certificates into Resty conveniently.
func (*Client) SetRootCertificate ¶ added in v1.12.1
SetRootCertificate method helps to add one or more root certificates into Resty client
client.SetRootCertificate("/path/to/root/pemFile.pem")
type MultipartField ¶ added in v1.12.1
MultipartField struct represent custom data part for multipart request
func NewMultipartField ¶ added in v1.12.1
type Option ¶ added in v1.12.1
type Option func(o *options)
func AddHeaders ¶ added in v1.12.1
func AuthScheme ¶ added in v1.12.1
func ChainInterceptor ¶
func ChainInterceptor(interceptors ...Interceptor) Option
func CheckRedirect ¶ added in v1.12.1
func CheckRedirect(policies ...RedirectPolicy) Option
func DoNotParseResponse ¶ added in v1.12.1
func EnableCloseConnection ¶ added in v1.12.1
func EnableJSONEscapeHTML ¶ added in v1.12.1
func PathParams ¶ added in v1.12.1
func QueryParam ¶ added in v1.12.1
func QueryParams ¶ added in v1.12.1
func SetHeaders ¶ added in v1.12.1
func SetOutputDirectory ¶ added in v1.12.1
func Transport ¶ added in v1.12.1
func Transport(transport http.RoundTripper) Option
type RedirectPolicy ¶ added in v1.12.1
RedirectPolicy to regulate the redirects in the resty client. Objects implementing the RedirectPolicy interface can be registered as
Apply function should return nil to continue the redirect jounery, otherwise return error to stop the redirect.
func DomainCheckRedirectPolicy ¶ added in v1.12.1
func DomainCheckRedirectPolicy(hostnames ...string) RedirectPolicy
DomainCheckRedirectPolicy is convenient method to define domain name redirect rule in resty client. Redirect is allowed for only mentioned host in the policy.
resty.SetRedirectPolicy(DomainCheckRedirectPolicy("host1.com", "host2.org", "host3.net"))
func FlexibleRedirectPolicy ¶ added in v1.12.1
func FlexibleRedirectPolicy(noOfRedirect int) RedirectPolicy
FlexibleRedirectPolicy is convenient method to create No of redirect policy for HTTP client.
resty.SetRedirectPolicy(FlexibleRedirectPolicy(20))
func NoRedirectPolicy ¶ added in v1.12.1
func NoRedirectPolicy() RedirectPolicy
NoRedirectPolicy is used to disable redirects in the HTTP client
resty.SetRedirectPolicy(NoRedirectPolicy())
type RedirectPolicyFunc ¶ added in v1.12.1
The RedirectPolicyFunc type is an adapter to allow the use of ordinary functions as RedirectPolicy. If f is a function with the appropriate signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls f.
type Response ¶ added in v1.12.1
type Response struct {
// contains filtered or unexported fields
}
func (*Response) IsError ¶ added in v1.12.1
IsError method returns true if HTTP status `code >= 400` otherwise false.
func (*Response) IsSuccess ¶ added in v1.12.1
IsSuccess method returns true if HTTP status `code >= 200 and <= 299` otherwise false.