requests

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 13 Imported by: 3

README

Requests

Go HTTP Client Library

Usage

// Default Request
url := "http://x.x.x.x"
requests.Get(url, nil)
requests.Get(url, map[string]string{"a": "1", "b": "2"})
requests.Post(url, map[string]interface{}{"a": "1", "b": "2"})
requests.PostForm(url, map[string]string{"a": "1", "b": "2"})
requests.Put(url, map[string]interface{}{"a": "1", "b": "2"})
requests.Delete(url)

// Default Session
loginUrl := "http://x.x.x.x/login"
s := requests.Session()
s.Post(loginUrl, map[string]interface{}{"user": "username", "password": "password"})
s.Get(url, nil)
s.Get(url, map[string]string{"a": "1", "b": "2"})
s.Post(url, map[string]interface{}{"a": "1", "b": "2"})
s.PostForm(url, map[string]string{"a": "1", "b": "2"})
s.Put(url, map[string]interface{}{"a": "1", "b": "2"})
s.Delete(url)

// New Request
r := NewRequest(DefaultConfig)
// New Session
s := NewSession(DefaultConfig)

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

View Source
var DefaultConfig = &Config{Timeout: 10 * time.Second}

Functions

This section is empty.

Types

type Config added in v1.0.3

type Config struct {
	Headers       map[string]string
	Proxy         map[string]string
	SkipTLSVerify bool
	Timeout       time.Duration
}

type Request added in v1.0.2

type Request struct {
	Req        *http.Request
	Client     *http.Client
	Resp       *http.Response
	Content    string
	StatusCode int
	Status     string
}

func Delete added in v1.0.5

func Delete(originUrl string) (*Request, error)

func Download added in v1.0.7

func Download(filepath, originUrl string) (*Request, error)

func Get

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

func NewRequest added in v1.0.2

func NewRequest(config *Config) *Request

func NewSession

func NewSession(config *Config) *Request

func Post

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

func PostForm

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

func Put added in v1.0.5

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

func Session added in v1.0.2

func Session() *Request

func (*Request) Delete added in v1.0.3

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

func (*Request) Download added in v1.0.7

func (r *Request) Download(filePath, originUrl string) 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) 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(headers 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) SkipTLSVerify added in v1.0.3

func (r *Request) SkipTLSVerify()

Jump to

Keyboard shortcuts

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