requests

package module
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 3

README

Requests

Go HTTP Client Library

Usage

// New Request
r := NewRequest(WithTimout(time.Second))

// New Session
r := NewSession(WithTimout(time.Second))

// do http method
r.Get(url, map[string]string{})
r.Post(url, map[string]interface{}{})
r.Post(url, map[string]interface{}{})
r.PostFrom(url, map[string]string{})
r.Put(url, map[string]interface{}{})
r.Delete(url, map[string]interface{}{})

// download
r.Download(filePath, originUrl)
r.DownloadWithRateLimit(filePath, originUrl, rate)

// upload
r.Upload(originUrl, map[string]string{}, filepath1, filepath2 ...)

// response
r.Content()
r.ContentToString()
r.Status() // status code, status
r.Resp() // raw http.Response

Documentation

Index

Constants

View Source
const (
	ContentTypeJson string = "application/json;charset=utf-8"
	ContentTypeForm string = "application/x-www-form-urlencoded"
	HttpGet         string = "GET"
	HttpPost        string = "POST"
	HttpPut         string = "PUT"
	HttpDelete      string = "DELETE"
)

Variables

This section is empty.

Functions

func DefaultTransport added in v1.2.3

func DefaultTransport() *http.Transport

func ProxyFromEnvironment added in v1.2.3

func ProxyFromEnvironment(req *http.Request) (*url.URL, error)

Types

type Option added in v1.1.5

type Option func(*Request)

func WithBasicAuth added in v1.1.5

func WithBasicAuth(username, password string) Option

func WithBearerTokenAuth added in v1.1.5

func WithBearerTokenAuth(token string) Option

func WithCancelProxy added in v1.2.5

func WithCancelProxy() Option

func WithHeader added in v1.1.5

func WithHeader(headers ...map[string]string) Option

func WithProxy added in v1.1.5

func WithProxy(proxy map[string]string) Option

func WithSkipTLSVerify added in v1.1.5

func WithSkipTLSVerify() Option

func WithTimeout added in v1.1.5

func WithTimeout(t time.Duration) Option

func WithTransport added in v1.2.4

func WithTransport(transport *http.Transport) Option

type Request added in v1.0.2

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest added in v1.0.2

func NewRequest(options ...Option) *Request

func NewSession

func NewSession(options ...Option) *Request

func (*Request) CancelProxy added in v1.2.5

func (r *Request) CancelProxy()

func (Request) Content added in v1.0.2

func (r Request) Content() []byte

func (Request) ContentToString added in v1.1.0

func (r Request) ContentToString() string

func (*Request) Delete added in v1.0.3

func (r *Request) Delete(originUrl string, data map[string]interface{}) error

func (*Request) Download added in v1.0.7

func (r *Request) Download(filePath, originUrl string) error

func (*Request) DownloadWithRateLimit added in v1.1.2

func (r *Request) DownloadWithRateLimit(filePath, originUrl string, rate int64) error

func (*Request) Get added in v1.0.2

func (r *Request) Get(originUrl string, params map[string]string) error

func (*Request) ParseUrl added in v1.0.2

func (r *Request) ParseUrl(originUrl string) error

func (*Request) Post added in v1.0.2

func (r *Request) Post(originUrl string, data map[string]interface{}) error

func (*Request) PostForm added in v1.0.2

func (r *Request) PostForm(originUrl string, data map[string]string) error

func (*Request) Put added in v1.0.3

func (r *Request) Put(originUrl string, data map[string]interface{}) error

func (Request) Request added in v1.2.1

func (r Request) Request() *http.Request

func (Request) Response added in v1.2.1

func (r Request) Response() *http.Response

func (*Request) SetBasicAuth added in v1.0.3

func (r *Request) SetBasicAuth(username, password string)

func (*Request) SetBearerTokenAuth added in v1.0.3

func (r *Request) SetBearerTokenAuth(token string)

func (*Request) SetHeader added in v1.0.3

func (r *Request) SetHeader(header map[string]string)

func (*Request) SetProxy added in v1.0.3

func (r *Request) SetProxy(proxy map[string]string)

func (*Request) SetTimeout added in v1.0.3

func (r *Request) SetTimeout(t time.Duration)

func (*Request) SetTransport added in v1.2.3

func (r *Request) SetTransport(transport *http.Transport)

func (*Request) SkipTLSVerify added in v1.0.3

func (r *Request) SkipTLSVerify()

func (Request) Status added in v1.0.2

func (r Request) Status() (int, string)

func (*Request) Upload added in v1.2.1

func (r *Request) Upload(originUrl string, data map[string]string, filePaths ...string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL