httpcli

package module
v0.0.0-...-c863939 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 12 Imported by: 1

README

httpcli

Simple http client in go, w some bonuses

Documentation

Overview

httpcli - Package with a simplified http client for the most common needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Cli      *http.Client
	BasePath string
	Headers  http.Header
	LastRes  *http.Response
}

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 Cli

func Cli() *Client

In case a singleton is enought, you can use this particular instance.

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) Do

func (c *Client) Do(method string, strurl string, body []byte) (*http.Response, error)

Do - This is the innermost function, and is really what DOES the http request.

func (*Client) DoJson

func (c *Client) DoJson(method string, strurl string, i interface{}, o interface{}) (err error)

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 (c *Client) GetSetCookie(ck string)

func (*Client) JsonDelete

func (c *Client) JsonDelete(strurl string, o interface{}) error

JsonDelete - Calls DoJson for a DELETE request.

func (*Client) JsonGet

func (c *Client) JsonGet(strurl string, o interface{}) error

JsonGet - Calls DoJson for a GET request.

func (*Client) JsonPatch

func (c *Client) JsonPatch(strurl string, i interface{}, o interface{}) error

JsonHead - Calls DoJson for a HEAD request

func (*Client) JsonPost

func (c *Client) JsonPost(strurl string, i interface{}, o interface{}) error

JsonPost - Calls DoJson for a POST request.

func (*Client) JsonPut

func (c *Client) JsonPut(strurl string, i interface{}, o interface{}) error

JsonPut - Calls DoJson for a PUT 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.

func (*Client) RawDelete

func (c *Client) RawDelete(strurl string) ([]byte, *http.Response, error)

RawDelete - Calls Do and returns body as byte slice.

func (*Client) RawGet

func (c *Client) RawGet(strurl string) ([]byte, *http.Response, error)

RawGet - Calls Do and returns body as byte slice.

func (*Client) RawHead

func (c *Client) RawHead(strurl string) (*http.Response, error)

RawHead - Calls Head

func (*Client) RawPost

func (c *Client) RawPost(strurl string, i []byte) ([]byte, *http.Response, error)

RawPost - Calls Do and returns body as byte slice.

func (*Client) RawPut

func (c *Client) RawPut(strurl string, i []byte) ([]byte, *http.Response, error)

RawPut - Calls Do and returns body as byte slice.

func (*Client) WS

func (c *Client) WS(strurl string) (*websocket.Conn, *http.Response, error)

WS - creates a websocket connection. returns the conn, the http response associated or an error.

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.

Jump to

Keyboard shortcuts

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