httpcli

package module
v0.0.0-...-dd5645e Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

README

httpcli

httpcli is better choice for http request.

License Go Report Card GoDoc Build Status Coverage Status

Brief

implements a friendly API for net/http standard library.

Features

  • simpler Get、Post request
  • decorate function param settings

Example

Get a page
	req := httpcli.Get("https://www.google.com").WithTLS()
	response, err := req.Response()
	if err != nil {
		fmt.Println("err:", err)
	} else {
		fmt.Println("result:",response.String())
	}
Post a req
	req := Post("https://baidu.com").WithTLS().
    		WithParam("wd", "查询")
	response, err := req.Response()
	if err != nil {
		fmt.Println("err:", err)
	} else {
		fmt.Println("result:",response.String())
	}

Documentation

Overview

Package httpcli is toolkit for simplification of http request

Index

Constants

View Source
const (
	HTTP1 = "HTTP/1.1"
	HTTP2 = "HTTP/2.0"
)

Variables

View Source
var ErrNilResponse = errors.New("nil response")

Functions

This section is empty.

Types

type Client

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

Client is a toolkit base on http.Client

func Get

func Get(url string) *Client

Get returns *Client with GET method.

func New

func New(req *http.Request) *Client

New return a Client with the underlying *http.Client.

func Post

func Post(url string) *Client

Post returns *Client with POST method.

func (*Client) Do

func (client *Client) Do() (err error)

Do just execute the request. return error if error happens.

func (*Client) GetBody

func (client *Client) GetBody() []byte

GetBody return the request body.

func (*Client) GetUrl

func (client *Client) GetUrl() string

GetUrl return the url of the request.

func (*Client) Info

func (client *Client) Info() string

Info return the client request information both response if it is not nil.

func (*Client) Request

func (client *Client) Request() *http.Request

Request return the raw *http.Client.

func (*Client) Response

func (client *Client) Response() (resp *response, err error)

Response execute the request and get the response, return error if error happens.

func (*Client) Undo

func (client *Client) Undo() *Client

Undo let the request could be executed again.

func (*Client) Url

func (client *Client) Url(urlStr string) *Client

Url set the request's url.

func (*Client) WithBody

func (client *Client) WithBody(body interface{}) *Client

WithBody set request body,support string and []byte.

func (*Client) WithHeader

func (client *Client) WithHeader(k, v string) *Client

WithHeader set the request header.

func (*Client) WithHeaders

func (client *Client) WithHeaders(params Params) *Client

WithHeaders set multiple headers.

func (*Client) WithJson

func (client *Client) WithJson(content string) *Client

func (*Client) WithParam

func (client *Client) WithParam(k, v string) *Client

WithParam set single param to the request.

func (*Client) WithParams

func (client *Client) WithParams(params Params) *Client

WithParams set multiple params to the request.

func (*Client) WithTLS

func (client *Client) WithTLS() *Client

WithTLS insecure the https.

type Params

type Params map[string]string

Params represents the request params.

type Proto

type Proto struct {
}

Jump to

Keyboard shortcuts

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