newclient

package
v2.17.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseResponse added in v2.6.0

func CloseResponse(response *http.Response)

CloseResponse closes a response body; If you use DoRequest, and not one of the higher level helpers like Get or Post, you should use `defer CloseResponse(response)` to ensure it gets cleaned up properly

func Delete added in v2.6.0

func Delete[TResponse any](httpSession *HttpSession, url string) (*TResponse, error)

func DoRequest added in v2.6.0

func DoRequest[TResponse any](httpSession *HttpSession, method string, path string, body any) (*TResponse, error)

func Get added in v2.6.0

func Get[TResponse any](httpSession *HttpSession, url string) (*TResponse, error)

func Post added in v2.6.0

func Post[TResponse any](httpSession *HttpSession, url string, body any) (*TResponse, error)

func Put added in v2.6.0

func Put[TResponse any](httpSession *HttpSession, url string, body any) (*TResponse, error)

Types

type Client

type Client interface {
	HttpSession() *HttpSession
	URITemplateCache() *uritemplates.URITemplateCache
}

func NewClient

func NewClient(httpSession *HttpSession) Client

type HttpSession added in v2.6.0

type HttpSession struct {
	HttpClient     *http.Client
	BaseURL        *url.URL
	DefaultHeaders map[string]string
}

HttpSession is a layer over http.Client, and provides the following additional functionality: - Holding a 'base' URL, and using it to qualify relative URL's - Holding default HTTP request headers, and propagating them onto - Converting payloads to/from JSON, including our behaviour of converting HTTP 4xx/5xx responses into go error structs - Helpers for convenient Get/Put/Post/etc - Dealing with quirks of the go io subsystem (flushing buffers where required etc).

While this borrows some ideas and quirk-handling from Sling, we don't want to use Sling itself because it has a weird API, and doesn't allow us access to some things that we need.

func (*HttpSession) DoRawJsonRequest added in v2.6.0

func (h *HttpSession) DoRawJsonRequest(req *http.Request, requestBody any, outputResponseBody any, outputResponseError error) (*http.Response, error)

DoRawJsonRequest layers JSON serialization over DoRawRequest outputResponseBody and outputResponseError should be pointers to structs which will receive unmarshaled JSON For most situations a higher level generic method like Get or Post will be better

func (*HttpSession) DoRawRequest added in v2.6.0

func (h *HttpSession) DoRawRequest(req *http.Request) (*http.Response, error)

DoRawRequest adds any default headers to the HTTP request, and resolve the URL against the baseURL, then performs the HTTP request. This is the bottom of the stack of abstraction layers; for most situations a higher level method will be preferable

Jump to

Keyboard shortcuts

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