httpclient

package
v0.0.0-...-69f973d Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON is the mimetype for json
	ContentTypeJSON = "application/json"
	// ContentTypeXML is the mimetype for xml
	ContentTypeXML = "application/xml"
	// DefaultAccept is the default Accept mimetype for requests
	DefaultAccept = "*/*"
)

Variables

View Source
var (
	// ErrInvalidStatusCode is the error type returned when the user sets expected
	// status code with `ExpectStatus`, but it does not match
	ErrInvalidStatusCode = errors.New("response had an invalid status code")
)

Functions

This section is empty.

Types

type Request

type Request struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Request represents an http request

func New

func New(opts ...RequestOption) (*Request, *http.Request, error)

New creates a ClientRequest

type RequestOption

type RequestOption func(*Request) error

RequestOption is a type for functional options

func Accept

func Accept(ct string) RequestOption

Accept allows setting the Accept header individually

func AddHeaders

func AddHeaders(h ...map[string]string) RequestOption

AddHeaders adds custom headers to the request

func ContentType

func ContentType(ct string) RequestOption

ContentType allows setting the content-type for the request

func ExpectStatus

func ExpectStatus(codes ...int) RequestOption

ExpectStatus sets expected status codes from a response

func JSON

func JSON() RequestOption

JSON sets a request to accept and respond with json

func QueryParams

func QueryParams(m map[string]string) RequestOption

QueryParams sets the query params for a request

func RequestXML

func RequestXML() RequestOption

RequestXML sets a request to accept and respond with json

func SetClient

func SetClient(client *http.Client) RequestOption

SetClient sets a custom http.Client to use for the request

func SetCookieJar

func SetCookieJar(jar *cookiejar.Jar) RequestOption

SetCookieJar sets the cookie jar to be used with requests

func WithBody

func WithBody(reader io.Reader) RequestOption

WithBody provides the body to be used with the http request

type Response

type Response struct {
	Body    []byte
	Headers http.Header
	Cookies []*http.Cookie
	Status  int
}

Response represents an http response

func Delete

func Delete(url string, opts ...RequestOption) (*Response, error)

Delete performs an http DELETE

func Get

func Get(url string, opts ...RequestOption) (*Response, error)

Get performs an http GET

func Head(url string, opts ...RequestOption) (*Response, error)

Head performs an http HEAD

func Post

func Post(url string, opts ...RequestOption) (*Response, error)

Post performs an http POST

func Put

func Put(url string, opts ...RequestOption) (*Response, error)

Put performs an http PUT

Jump to

Keyboard shortcuts

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