https://github.com/fako1024/fhttpc
A simple wrapper around the Go fasthttp client optimized for ease-of-use
https://github.com/fako1024/fhttpc
fasthttp fasthttpclient http-client method-chaining
Last synced: 7 months ago
JSON representation
A simple wrapper around the Go fasthttp client optimized for ease-of-use
- Host: GitHub
- URL: https://github.com/fako1024/fhttpc
- Owner: fako1024
- License: apache-2.0
- Created: 2024-09-07T07:59:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-26T13:28:09.000Z (about 1 year ago)
- Last Synced: 2025-02-22T08:34:45.125Z (11 months ago)
- Topics: fasthttp, fasthttpclient, http-client, method-chaining
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A simple wrapper around the Go fasthttp client optimized for ease-of-use
[](https://github.com/fako1024/fhttpc/releases)
[](https://godoc.org/github.com/fako1024/fhttpc/)
[](https://goreportcard.com/report/github.com/fako1024/fhttpc)
[](https://github.com/fako1024/fhttpc/actions?query=workflow%3AGo)
[](https://github.com/fako1024/fhttpc/actions/workflows/codeql-analysis.yml)
This package wraps the Go [fasthttp](https://github.com/valyala/fasthttp) client, providing a simplified interaction model using method chaining and various additional capabilities.
## Features
- Simple, method chaining based interface for fasthttp client requests
- Simulation of request delays
- Customization of fasthttp client via functional parameter
- Back-Off-Retry concept to automatically retry requests if required
## Installation
```bash
go get -u github.com/fako1024/fhttpc
```
## Examples
#### Perform simple HTTP GET request
```go
err := fhttpc.New("GET", "http://example.org").Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}
```
#### Perform HTTP GET request and parse the result as JSON into a struct
```go
var res = struct {
Status int
Message string
}{}
err := fhttpc.New("GET", "http://example.org").
ParseJSON(&res).
Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}
```
#### Perform HTTPS POST request with a simple body, disabling certificate validation and copying the response to a bytes.Buffer
```go
buf := new(bytes.Buffer)
err := fhttpc.New("POST", "https://example.org").
SkipCertificateVerification().
Body([]byte{0x1, 0x2}).
ParseFn(fhttpc.Copy(buf)).
Run()
if err != nil {
log.Fatalf("error performing POST request: %s", err)
}
fmt.Println(buf.String())
```
#### Perform HTTPS GET request (with query parameters + headers + basic auth)
```go
err := fhttpc.New("GET", "https://example.org").
SkipCertificateVerification().
QueryParams(fhttpc.Params{
"param": "test",
}).
Headers(fhttpc.Params{
"X-HEADER-TEST": "test",
}).
AuthBasic("username", "password").
Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}
```