Documentation
¶
Overview ¶
Package rest provides a simple HTTP client for REST APIs.
Index ¶
- type Client
- func (c *Client) Delete(path string, response any) *Error
- func (c *Client) Do(req *http.Request, response any) *Error
- func (c *Client) DoWithBody(method, path string, body any, response any) *Error
- func (c *Client) DoWithoutBody(method, path string, response any) *Error
- func (c *Client) Get(path string, response any) *Error
- func (c *Client) Patch(path string, body any, response any) *Error
- func (c *Client) Post(path string, body any, response any) *Error
- func (c *Client) Put(path string, body any, response any) *Error
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a simple HTTP client for REST APIs.
func (*Client) Delete ¶
Delete makes a DELETE request to the given path and unmarshals the response into the given response object.
- path: the path to make the request to
- response: a pointer to the struct to unmarshal the response into
func (*Client) DoWithBody ¶
DoWithBody makes a request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.
- method: the HTTP method to use (e.g. GET, POST, PUT, DELETE)
- path: the path to make the request to
- body: the body to send with the request
- response: a pointer to the struct to unmarshal the response into
func (*Client) DoWithoutBody ¶
DoWithoutBody makes a request to the given path and unmarshals the response into the given response object.
- method: the HTTP method to use (e.g. GET, POST, PUT, DELETE)
- path: the path to make the request to
- response: a pointer to the struct to unmarshal the response into
func (*Client) Get ¶
Get makes a GET request to the given path and unmarshals the response into the given response object.
- path: the path to make the request to
- response: a pointer to the struct to unmarshal the response into
func (*Client) Patch ¶
Patch makes a PATCH request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.
func (*Client) Post ¶
Post makes a POST request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.