request

package
v4.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 10 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(req *http.Request) (*http.Response, error)

Do send request with default client

func DoWithClient

func DoWithClient(client http.Client, req *http.Request) (*http.Response, error)

DoWithClient send request with given client

func ReadBodyRequest

func ReadBodyRequest(r *http.Request) ([]byte, error)

ReadBodyRequest return content of a body request (defined as a ReadCloser)

func ReadBodyResponse

func ReadBodyResponse(r *http.Response) ([]byte, error)

ReadBodyResponse return content of a body response (defined as a ReadCloser)

Types

type Request

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

Request describe a complete request

func New

func New() *Request

New create a new Request

func (*Request) BasicAuth

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

BasicAuth add Basic Auth header

func (*Request) Build

func (r *Request) Build(ctx context.Context, payload io.Reader) (*http.Request, error)

Build create request for given context and payload

func (*Request) ContentForm

func (r *Request) ContentForm() *Request

ContentForm set Content-Type header to application/x-www-form-urlencoded

func (*Request) ContentJSON

func (r *Request) ContentJSON() *Request

ContentJSON set Content-Type header to application/json

func (*Request) ContentType

func (r *Request) ContentType(contentType string) *Request

ContentType set Content-Type header

func (*Request) Delete

func (r *Request) Delete(url string) *Request

Delete set DELETE to given url

func (*Request) Form

func (r *Request) Form(ctx context.Context, data url.Values) (*http.Response, error)

Form send request with given context and url.Values as payload

func (*Request) Get

func (r *Request) Get(url string) *Request

Get set GET to given url

func (*Request) Header

func (r *Request) Header(name, value string) *Request

Header add header to request

func (*Request) JSON

func (r *Request) JSON(ctx context.Context, body interface{}) (*http.Response, error)

JSON send request with given context and given interface as JSON payload

func (*Request) Method

func (r *Request) Method(method string) *Request

Method set method of Request

func (*Request) Patch

func (r *Request) Patch(url string) *Request

Patch set PATCH to given url

func (*Request) Post

func (r *Request) Post(url string) *Request

Post set POST to given url

func (*Request) Put

func (r *Request) Put(url string) *Request

Put set PUT to given url

func (*Request) Send

func (r *Request) Send(ctx context.Context, payload io.Reader) (*http.Response, error)

Send build request and send it with defined client

func (*Request) URL

func (r *Request) URL(url string) *Request

URL set URL of Request

func (*Request) WithClient

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

WithClient defines net/http client to use, instead of default one (30sec timeout and no redirect)

Jump to

Keyboard shortcuts

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