https://github.com/opus-domini/fast-shot
Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client.
https://github.com/opus-domini/fast-shot
go golang golang-library http-client rest
Last synced: 9 months ago
JSON representation
Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client.
- Host: GitHub
- URL: https://github.com/opus-domini/fast-shot
- Owner: opus-domini
- License: mit
- Created: 2023-09-16T05:29:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-19T03:59:28.000Z (over 1 year ago)
- Last Synced: 2024-08-19T04:55:53.182Z (over 1 year ago)
- Topics: go, golang, golang-library, http-client, rest
- Language: Go
- Homepage:
- Size: 1.22 MB
- Stars: 48
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - opus-domini/fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Go)
- awesome-go - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- awesome-go-cn - fast-shot - fire precision using Go's fastest and simple HTTP Client. [![godoc][D]](https://godoc.org/github.com/opus-domini/fast-shot) (网络 / HTTP客户端)
- awesome-go-plus - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client.  (Networking / HTTP Clients)
- awesome-go - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- awesome-go - opus-domini/fast-shot - fire precision using Go's fastest and simple HTTP Client. ☆`94` (Networking / HTTP Clients)
- awesome-go-with-stars - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- awesome-go - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- awesome-go - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- fucking-awesome-go - fast-shot - Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client. (Networking / HTTP Clients)
- awesome-go-cn - fast-shot - fire precision using Go's fastest and simple HTTP Client. [![godoc][D]](https://godoc.org/github.com/opus-domini/fast-shot) (网络 / HTTP客户端)
README
Fast Shot is a robust, feature-rich, and highly configurable HTTP client for Go. Crafted with modern Go practices in mind, it offers a fluent, chainable API that allows for clean, idiomatic code.
## Table of Contents
- [Why Fast Shot?](#why-fast-shot)
- [Features](#features-)
- [Installation](#installation-)
- [Quick Start](#quick-start-)
- [Advanced Usage](#advanced-usage-)
- [Contributing](#contributing-)
## Why Fast Shot?
* **Fluent & Chainable API**: Write expressive, readable, and flexible HTTP client code.
* **Ease of Use**: Reduce boilerplate, making HTTP requests as straightforward as possible.
* **Rich Features**: From headers to query parameters and JSON support, Fast Shot covers your needs.
* **Advanced Retry Mechanism**: Built-in support for retries with various backoff strategies.
## Features 🌟
* Fluent and chainable API for clean, expressive code
* Comprehensive HTTP method support (GET, POST, PUT, DELETE, etc.)
* Flexible authentication options (Bearer Token, Basic Auth, Custom)
* Easy manipulation of headers, cookies, and query parameters
* Advanced retry mechanism with customizable backoff strategies
* Client-side load balancing for improved reliability
* JSON request and response support
* XML request and response support
* Timeout and redirect control
* Proxy support
* Extensible and customizable for specific needs
* Well-tested and production-ready
## Installation 🔧
To install Fast Shot, run the following command:
```bash
go get github.com/opus-domini/fast-shot
```
## Quick Start 🚀
Here's how you can make a simple POST using Fast Shot:
```go
package main
import (
"fmt"
fastshot "github.com/opus-domini/fast-shot"
"github.com/opus-domini/fast-shot/constant/mime"
)
func main() {
client := fastshot.NewClient("https://api.example.com").
Auth().BearerToken("your_token_here").
Build()
payload := map[string]interface{}{
"key1": "value1",
"key2": "value2",
}
response, err := client.POST("/endpoint").
Header().AddAccept(mime.JSON).
Body().AsJSON(payload).
Send()
// Check for request send problems.
if err != nil {
panic(err) // (¬_¬")
}
// Check for (4xx || 5xx) errors response.
if response.Status().IsError() {
panic(response.Body().AsString()) // ¯\_(ツ)_/¯
}
var result map[string]interface{}
_ := response.Body().AsJSON(&result)
// Congrats! Do something awesome with the result (¬‿¬)
}
```
## Advanced Usage 🤖
### Fluent API
Easily chain multiple settings in a single line:
```go
client := fastshot.NewClient("https://api.example.com").
Auth().BearerToken("your-bearer-token").
Header().Add("My-Header", "My-Value").
Config().SetTimeout(30 * time.Second).
Build()
```
### Advanced Retry Mechanism
Handle transient failures with customizable backoff strategies:
```go
client.POST("/resource").
Retry().SetExponentialBackoff(2 * time.Second, 5, 2.0).
Send()
```
This new retry feature supports:
- Constant backoff
- Exponential backoff
- Full jitter for both constant and exponential backoff
- Custom retry conditions
- Maximum delay setting
### Out-of-the-Box Support for Client Load Balancing
Effortlessly manage multiple endpoints:
```go
client := fastshot.NewClientLoadBalancer([]string{
"https://api1.example.com",
"https://api2.example.com",
"https://api3.example.com",
}).
Config().SetTimeout(time.Second * 10).
Build()
```
This feature allows you to distribute network traffic across several servers, enhancing the performance and reliability of your applications.
### Authentication
Fast Shot supports various types of authentication:
```go
// Bearer Token
builder.Auth().BearerToken("your-bearer-token")
// Basic Authentication
builder.Auth().BasicAuth("username", "password")
// Custom Authentication
builder.Auth().Set("custom-authentication-header")
```
### Custom Headers and Cookies
Add your own headers and cookies effortlessly:
```go
// Add Custom Header
builder.Header().
Add("header", "value")
// Add Multiple Custom Headers
builder.Header().
AddAll(map[string]string{
"key1": "value1",
"key2": "value2",
"key3": "value3",
})
// Add Custom Cookie
builder.Cookie().
Add(&http.Cookie{Name: "session_id", Value: "id"})
```
### Advanced Configurations
Control every aspect of the HTTP client:
```go
// Set Timeout
builder.Config().
SetTimeout(time.Second * 30)
// Set Follow Redirect
builder.Config().
SetFollowRedirects(false)
// Set Custom Transport
builder.Config().
SetCustomTransport(myCustomTransport)
// Set Proxy
builder.Config().
SetProxy("http://my-proxy-server:port")
```
### Response Handling
Extract information from the response with ease:
```go
// Fluent response status check
response.Status()
// Easy response body access and conversion
response.Body()
// Get response headers to inspect
response.Header()
// Get response cookies for further processing
response.Cookie()
// Get raw response if needed
response.Raw()
// and more...
```
## Contributing 🤝
We welcome contributions to Fast Shot! Here's how you can contribute:
1. Fork the repository
2. Create a new branch for your feature or bug fix
3. Write your code and tests
4. Ensure all tests pass
5. Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.
For more detailed information, check out our [CONTRIBUTING.md](https://github.com/opus-domini/fast-shot/blob/main/CONTRIBUTING.md) file.
## Stargazers over time ⭐
[](https://starchart.cc/opus-domini/fast-shot)