rest

package
v0.0.0-...-e7ae2a8 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Helper package to handle drudgery of REST request handling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeaders

func AddHeaders(key, value string) func(*Request)

func AddJSONMimeType

func AddJSONMimeType() func(*Request)

func AllowSelfSignedCerts

func AllowSelfSignedCerts() func(*Request)

Types

type Request

type Request struct {
	*http.Request
	*http.Client
	*http.Transport
}

type Response

type Response struct {
	*http.Response
	Error error
}

func Delete

func Delete(urlStr string, options ...func(*Request)) (*Response, error)

Delete sends a HTTP DELETE request to the provided URL.

func Get

func Get(urlStr string, options ...func(*Request)) (*Response, error)

Get sends a HTTP GET request to the provided url. options are run prior to the request being sent

addAuth := func(r *Request) {
        r.SetBasicAuth("username", "password")
}

resp, err := requests.Get("http://ilo.com/redfish", addAuth)
if err != nil {
        panic(err)
}
fmt.Println(resp.StatusCode)

func Post

func Post(urlStr string, body io.Reader, options ...func(*Request)) (*Response, error)

Post sends a HTTP POST request to the provided url. and option should be include to set the correct content-type header

addMimeType := func(r *Request) {
        r.Header.Add("content-type", "application/json")
}

resp, err := requests.Post("https://ilo.com/login", buf, redirect)

if err != nil {
        panic(err)
}

fmt.Println(resp.JSON())

func (*Response) Bytes

func (r *Response) Bytes() []byte

Bytes returns the response's Body as []byte.

func (*Response) JSON

func (r *Response) JSON() []byte

JSON returns the response's body as pretty printed []byte

func (*Response) Unmarshall

func (r *Response) Unmarshall(t interface{}) error

Unmarshall expected json response into passed interface type

Jump to

Keyboard shortcuts

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