Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/windy-server/hrq" ) func main() { req, _ := hrq.Get("http://example.com") res, _ := req.Send() s, _ := res.Text() fmt.Print(s) }
Output:
Index ¶
- Variables
- func MakeURL(baseURL string, params map[string]string) string
- type File
- type Request
- func Delete(url string) (req *Request, err error)
- func Get(url string) (req *Request, err error)
- func Head(url string) (req *Request, err error)
- func NewRequest(method, url string, body io.Reader, timeoutSecond int) (req *Request, err error)
- func Options(url string) (req *Request, err error)
- func Post(url string, data interface{}) (req *Request, err error)
- func Put(url string, data interface{}) (req *Request, err error)
- func (r *Request) AcceptGzip() *Request
- func (r *Request) AddFile(contentType, fieldName, fileName string, file *os.File) *Request
- func (r *Request) DelHeader(key string) *Request
- func (r *Request) DumpHeader() (dump string, err error)
- func (r *Request) HeaderValue(key string) string
- func (r *Request) PutCookie(name, value string) *Request
- func (r *Request) Send() (res *Response, err error)
- func (r *Request) SetApplicationFormUrlencoded() *Request
- func (r *Request) SetApplicationJSON() *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetMultipartFormData() *Request
- func (r *Request) SetTimeout(timeout int) *Request
- func (r *Request) UseGzip() *Request
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) Content() (bs []byte, err error)
- func (r *Response) ContentType() string
- func (r *Response) CookieValue(name string) string
- func (r *Response) CookiesMap() map[string]string
- func (r *Response) DumpHeader() (dump string, err error)
- func (r *Response) Encode() (encode string, err error)
- func (r *Response) HeaderValue(name string) string
- func (r *Response) JSON(t interface{}) error
- func (r *Response) Text() (text string, err error)
- func (r *Response) URL() *url.URL
- type Session
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultContentType = applicationFormUrlencoded
DefaultContentType is a default content-type of request.
var DefaultTimeout = 15
DefaultTimeout is seconds of timeout.
Functions ¶
Types ¶
type Request ¶
type Request struct { *http.Request Timeout time.Duration Data interface{} Files []*File // Gzip is a flag to decide whether to compress by gzip or not. // (defaut false) Gzip bool }
Request inherits http.Request.
func NewRequest ¶
NewRequest make a Request.
func (*Request) AcceptGzip ¶
AcceptGzip is an alias of req.SetHeader("Accept-Encoding", "gzip"). hrq automatically decompress request body.
func (*Request) DumpHeader ¶
DumpHeader returns a header string.
func (*Request) HeaderValue ¶
HeaderValue returns a value of request header.
func (*Request) PutCookie ¶
PutCookie makes a cookie which is setted name and value. It adds a cookie to a request.
func (*Request) Send ¶
Send sends request. If method is POST and content-type is application/x-www-form-urlencoded, the request data is urlencoded. If method is POST and content-type is application/json, the request data is converted to json string.
func (*Request) SetApplicationFormUrlencoded ¶
SetApplicationFormUrlencoded is an alias of req.SetHeader("Content-Type", "application/x-www-form-urlencoded").
func (*Request) SetApplicationJSON ¶
SetApplicationJSON is an alias of req.SetHeader("Content-Type", "application/json").
func (*Request) SetMultipartFormData ¶
SetMultipartFormData is an alias of req.SetHeader("Content-Type", "multipart/form-data").
func (*Request) SetTimeout ¶
SetTimeout sets timeout.
type Response ¶
type Response struct { *http.Response // History is the redirect history. History []*http.Request // contains filtered or unexported fields }
Response inherits http.Response.
func (*Response) ContentType ¶
ContentType returns content-type in response header..
func (*Response) CookieValue ¶
CookieValue returns a cookie value.
func (*Response) CookiesMap ¶
CookiesMap returns the response cookies by map.
func (*Response) DumpHeader ¶
DumpHeader returns a header string.
func (*Response) HeaderValue ¶
HeaderValue returns header value.
type Session ¶
Session is a session.
func (*Session) CookieValue ¶
CookieValue returns a cookie value.