newclient

package
v2.44.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v2.33.0

func Add[TResource any](client Client, template string, spaceID string, resource any) (*TResource, error)

Add creates a new resource.

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(httpSession *HttpSession, url string) error

func DeleteByID added in v2.33.0

func DeleteByID(client Client, template string, spaceID string, id string) error

DeleteByID will delete a resource with the provided id.

func DoDelete added in v2.33.0

func DoDelete(httpSession *HttpSession, method string, path string) 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 GetAll added in v2.34.0

func GetAll[TResource any](client Client, template string, spaceID string) ([]*TResource, error)

GetAll returns all resources. If an error occurs, it returns nil.

func GetByID added in v2.33.0

func GetByID[TResource any](client Client, template string, spaceID string, ID string) (*TResource, error)

GetByID returns the resource that matches the input ID.

func GetByQuery added in v2.33.0

func GetByQuery[TResource any](client Client, template string, spaceID string, query any) (*resources.Resources[*TResource], error)

GetByQuery returns a collection of resources based on the criteria defined by its input query parameter.

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)

func Update added in v2.33.0

func Update[TResource any](client Client, template string, spaceID string, ID string, resource any) (*TResource, error)

Update modifies a resource based on the one provided as input.

Types

type Client

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

func NewClient

func NewClient(httpSession *HttpSession) Client

func NewClientS added in v2.33.0

func NewClientS(httpSession *HttpSession, spaceID string) 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