Documentation ¶
Overview ¶
httpcli - Package with a simplified http client for the most common needs.
Index ¶
- type Client
- func (c *Client) Do(method string, strurl string, body []byte) (*http.Response, error)
- func (c *Client) DoJson(method string, strurl string, i interface{}, o interface{}) (err error)
- func (c *Client) GetSetCookie(ck string)
- func (c *Client) JsonDelete(strurl string, o interface{}) error
- func (c *Client) JsonGet(strurl string, o interface{}) error
- func (c *Client) JsonPatch(strurl string, i interface{}, o interface{}) error
- func (c *Client) JsonPost(strurl string, i interface{}, o interface{}) error
- func (c *Client) JsonPut(strurl string, i interface{}, o interface{}) error
- func (c *Client) Multipart(strurl string, params map[string]string, paramName, path string) (res *http.Response, err error)
- func (c *Client) MultipartJson(strurl string, params map[string]string, paramName, path string, o interface{}) (err error)
- func (c *Client) RawDelete(strurl string) ([]byte, *http.Response, error)
- func (c *Client) RawGet(strurl string) ([]byte, *http.Response, error)
- func (c *Client) RawHead(strurl string) (*http.Response, error)
- func (c *Client) RawPost(strurl string, i []byte) ([]byte, *http.Response, error)
- func (c *Client) RawPut(strurl string, i []byte) ([]byte, *http.Response, error)
- func (c *Client) WS(strurl string) (*websocket.Conn, *http.Response, error)
- type SimpleCookieJar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client represents the http client itself, but wraps the original http.Client within it. Headers property are standard headers you want to send with every request. Basepath is the url prefix, in case this client will do all calls to the same endpoint. This is usefull when you may need to switch endpoints, like DEV/QAS/PRD, but all remainder path portion remains the same.
func New ¶
func New() *Client
New - creates a new Client. Since we rely on std lib client, this is also thread safe, so no need to create multiple ones.
func (*Client) DoJson ¶
DoJson - calls Do, but sends i as json string in the body in case of method not being GET or HEAD or DELETE and serializes Body response in o, considering response will be a json object.
func (*Client) GetSetCookie ¶
func (*Client) JsonDelete ¶
JsonDelete - Calls DoJson for a DELETE request.
func (*Client) Multipart ¶
func (c *Client) Multipart(strurl string, params map[string]string, paramName, path string) (res *http.Response, err error)
Multipart does a multipart request, eventually sending also a file.
func (*Client) MultipartJson ¶
func (c *Client) MultipartJson(strurl string, params map[string]string, paramName, path string, o interface{}) (err error)
MultipartJson does a multipart request, eventually sending also a file, returns body in o.
type SimpleCookieJar ¶
type SimpleCookieJar struct {
// contains filtered or unexported fields
}
func (*SimpleCookieJar) Cookies ¶
func (s *SimpleCookieJar) Cookies(u *url.URL) []*http.Cookie
Cookies returns the cookies to send in a request for the given URL. It is up to the implementation to honor the standard cookie use restrictions such as in RFC 6265.
func (*SimpleCookieJar) SetCookies ¶
func (s *SimpleCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)
SetCookies handles the receipt of the cookies in a reply for the given URL. It may or may not choose to save the cookies, depending on the jar's policy and implementation.