Documentation ¶
Index ¶
- func Add[TResource any](client Client, template string, spaceID string, resource any) (*TResource, error)
- func CloseResponse(response *http.Response)
- func Delete(httpSession *HttpSession, url string) error
- func DeleteByID(client Client, template string, spaceID string, id string) error
- func DoDelete(httpSession *HttpSession, method string, path string) error
- func DoRequest[TResponse any](httpSession *HttpSession, method string, path string, body any) (*TResponse, error)
- func Get[TResponse any](httpSession *HttpSession, url string) (*TResponse, error)
- func GetByID[TResource any](client Client, template string, spaceID string, ID string) (*TResource, error)
- func GetByQuery[TResource any](client Client, template string, spaceID string, query any) (*resources.Resources[*TResource], error)
- func Post[TResponse any](httpSession *HttpSession, url string, body any) (*TResponse, error)
- func Put[TResponse any](httpSession *HttpSession, url string, body any) (*TResponse, error)
- func Update[TResource any](client Client, template string, spaceID string, ID string, resource any) (*TResource, error)
- type Client
- type HttpSession
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
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
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 Get ¶ added in v2.6.0
func Get[TResponse any](httpSession *HttpSession, url string) (*TResponse, error)
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)
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
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