https://github.com/skamenetskiy/hc
A handy http client on top of fasthttp.
https://github.com/skamenetskiy/hc
fasthttp golang httpclient
Last synced: 12 months ago
JSON representation
A handy http client on top of fasthttp.
- Host: GitHub
- URL: https://github.com/skamenetskiy/hc
- Owner: skamenetskiy
- Created: 2018-05-29T21:50:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-29T22:39:58.000Z (about 8 years ago)
- Last Synced: 2025-05-24T08:42:11.567Z (about 1 year ago)
- Topics: fasthttp, golang, httpclient
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hc
[](https://travis-ci.org/skamenetskiy/hc)
[](https://codecov.io/gh/skamenetskiy/hc)
hc stands for "http client". It is built on top of
[fasthttp](https://github.com/valyala/fasthttp) and provides some handy
shortcuts to http client methods.
## Usage
```go
const (
MethodGet = "GET"
MethodPost = "POST"
MethodPut = "PUT"
MethodDelete = "DELETE"
DefaultReadTimeout = time.Duration(0)
DefaultWriteTimeout = time.Duration(0)
)
```
#### func Delete
```go
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
```go
func Get(url string) (int, []byte, error)
```
Get makes a GET request to url and returns: http status code, response body,
error
#### func MakeRawRequest
```go
func MakeRawRequest(req *Request, res *Response) error
```
MakeRequest is doing a request using req and res and returns an error
#### func Post
```go
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
```go
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
```go
func SetReadTimeout(t time.Duration)
```
SetReadTimeout sets the client ReadTimeout
#### func SetWriteTimeout
```go
func SetWriteTimeout(t time.Duration)
```
SetWriteTimeout sets the client WriteTimeout
#### type Headers
```go
type Headers map[string]string
```
Headers key/value map if headers
#### func (Headers) Add
```go
func (h Headers) Add(k string, v string)
```
Add adds a header to Headers
#### type Request
```go
type Request struct {
*fasthttp.Request
}
```
Request request object
#### func AcquireRequest
```go
func AcquireRequest() *Request
```
AcquireRequest returns a new Request
#### func (*Request) WriteJSON
```go
func (r *Request) WriteJSON(v interface{}) error
```
WriteJSON will write v (as json) to Request body
#### type Response
```go
type Response struct {
*fasthttp.Response
}
```
Response response object
#### func AcquireResponse
```go
func AcquireResponse() *Response
```
AcquireResponse returns a new response
#### func MakeRequest
```go
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
```go
func (r *Response) ReadJSON(v interface{}) error
```
ReadJSON will read json into v from Response body