Skip to content

A handy http client on top of fasthttp.

Notifications You must be signed in to change notification settings

skamenetskiy/hc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hc

Build Status codecov

hc stands for "http client". It is built on top of fasthttp and provides some handy shortcuts to http client methods.

Usage

const (
	MethodGet    = "GET"
	MethodPost   = "POST"
	MethodPut    = "PUT"
	MethodDelete = "DELETE"

	DefaultReadTimeout  = time.Duration(0)
	DefaultWriteTimeout = time.Duration(0)
)

func Delete

func Delete(url string, body []byte, headers Headers) (int, []byte, error)

Delete makes a DELETE request to url, sends body in request body, sends headers and returns http status code, response body, error

func Get

func Get(url string) (int, []byte, error)

Get makes a GET request to url and returns: http status code, response body, error

func MakeRawRequest

func MakeRawRequest(req *Request, res *Response) error

MakeRequest is doing a request using req and res and returns an error

func Post

func Post(url string, body []byte, headers Headers) (int, []byte, error)

Post makes a POST request to url, sends body in request body, sends headers and returns http status code, response body, error

func Put

func Put(url string, body []byte, headers Headers) (int, []byte, error)

Put makes a PUT request to url, sends body in request body, sends headers and returns http status code, response body, error

func SetReadTimeout

func SetReadTimeout(t time.Duration)

SetReadTimeout sets the client ReadTimeout

func SetWriteTimeout

func SetWriteTimeout(t time.Duration)

SetWriteTimeout sets the client WriteTimeout

type Headers

type Headers map[string]string

Headers key/value map if headers

func (Headers) Add

func (h Headers) Add(k string, v string)

Add adds a header to Headers

type Request

type Request struct {
	*fasthttp.Request
}

Request request object

func AcquireRequest

func AcquireRequest() *Request

AcquireRequest returns a new Request

func (*Request) WriteJSON

func (r *Request) WriteJSON(v interface{}) error

WriteJSON will write v (as json) to Request body

type Response

type Response struct {
	*fasthttp.Response
}

Response response object

func AcquireResponse

func AcquireResponse() *Response

AcquireResponse returns a new response

func MakeRequest

func MakeRequest(method string, url string, body []byte, headers Headers) (*Response, error)

MakeRequest makes a new request using method to url, sends body in post body, sends headers in headers and returns Response object and/or error

func (*Response) ReadJSON

func (r *Response) ReadJSON(v interface{}) error

ReadJSON will read json into v from Response body

About

A handy http client on top of fasthttp.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages