module
Version:
v1.2.3
Opens a new window with list of versions in this module.
Published: Jul 18, 2024
License: MIT
Opens a new window with license information.
README
¶
FastHttpClient

FastHttpClient is a lightweight and high-performance HTTP client for sending requests.
Features
- Simple and intuitive API
- Fast and efficient
- Supports various HTTP methods (GET, POST, PUT, DELETE, etc.)
- Use as Package
- Client with Rate Limiting option
Usage
-
Add project to dependency
go get github.com/dmdhrumilmistry/fasthttpclient
-
Without Rate Limit
package main
import (
"log"
"github.com/dmdhrumilmistry/fasthttpclient/client"
"github.com/valyala/fasthttp"
)
func main() {
// Create a new FHClient without any rate limit
fhc := client.NewFHClient(&fasthttp.Client{})
queryParams := map[string]string{
"queryParam1": "value1",
"queryParam2": "value2",
}
// use fhc to make a GET request
resp, err := client.Get(fhc, "https://example.com", queryParams, nil)
if err != nil {
log.Fatalln(err)
}
log.Println(resp.StatusCode)
log.Println(resp.Headers)
log.Println(string(resp.Body))
log.Println(resp.CurlCommand)
}
-
Using Rate Limit 100 requests/1sec
package main
import (
"log"
"github.com/dmdhrumilmistry/fasthttpclient/client"
"github.com/valyala/fasthttp"
)
func main() {
// Create a new RateLimitedClient with 100 requests per second
rlclient := client.NewRateLimitedClient(100, 1, &fasthttp.Client{})
queryParams := map[string]string{
"queryParam1": "value1",
"queryParam2": "value2",
}
headers := map[string]string{
"Content-Type": "application/json",
}
body := []byte(`{"key": "value"}`)
resp, err := client.Post(rlclient, "https://example.com", queryParams, headers, body)
if err != nil {
log.Fatalln(err)
}
log.Println(resp.StatusCode)
log.Println(resp.Headers)
log.Println(string(resp.Body))
log.Println(resp.CurlCommand)
}
-
View all examples
Directories
¶
|
|
examples
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.