requests

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	Key   string
	Value string
}

type QueryParam

type QueryParam struct {
	Key   string
	Value string
}

type RESTRequest

type RESTRequest struct {
	URI         string
	Method      string
	Endpoint    string
	QueryParams []QueryParam
	Headers     []Header
	Payload     interface{}
}

func (*RESTRequest) BuildHTTPRequest

func (r *RESTRequest) BuildHTTPRequest() (*http.Request, error)

BuildHTTPRequest constructs the complete net/http object which is needed to perform a final HTTP request.

It is not necessary to use this function, but it may be useful if the net.Request object needs to be inspected or modified for advanced use cases.

func (*RESTRequest) Submit

func (r *RESTRequest) Submit() (*RESTResponse, error)

Submit performs the HTTP request, returning a resultant RESTResponse Usage:

request = &RESTRequest{ ... }
response, _ := request.Submit()

func (*RESTRequest) SubmitStrict

func (r *RESTRequest) SubmitStrict() (*RESTResponse, error)

SubmitStrict performs the HTTP request, returning a resultant RESTResponse if the response's status code is < 400. Usage:

request = &RESTRequest{ ... }
response, _ := request.Submit()

type RESTResponse

type RESTResponse struct {
	StatusCode int
	Headers    []Header
	Payload    []byte
}

func (*RESTResponse) PayloadAsPrettyJSONString

func (r *RESTResponse) PayloadAsPrettyJSONString() (string, error)

PayloadAsPrettyJSONString returns the response body as a formatted JSON string The response body must be valid JSON in the form either of a list or a map.

func (*RESTResponse) PayloadAsString

func (r *RESTResponse) PayloadAsString() (string, error)

PayloadAsString returns the response body as a string.

func (*RESTResponse) UnmarshalPayload

func (r *RESTResponse) UnmarshalPayload(v interface{}) error

UnmarshalPayload converts the raw response body into the given interface Usage:

var foo MyStruct
response.UnmarshalPayload(&foo)

type RESTResponseError

type RESTResponseError struct {
	RequestURI         string
	ResponseStatusCode int
}

func (*RESTResponseError) Error

func (e *RESTResponseError) Error() string

Jump to

Keyboard shortcuts

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