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.
- 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.
- Fluent API for HTTP requests
- Extensible authentication
- Customizable HTTP headers
- Query parameter manipulation
- JSON request and response support
- Built-in error handling
- Well-tested
To install Fast Shot, run the following command:
go get github.com/opus-domini/fast-shot
Here's how you can make a simple POST using Fast Shot:
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()
// Process response...
}
Easily chain multiple settings in a single line:
client := fastshot.NewClient("https://api.example.com").
Auth().BearerToken("your-bearer-token").
Header().Add("My-Header", "My-Value").
Config().SetTimeout(time.Second * 30).
Build()
Handle transient failures, enhancing the reliability of your HTTP requests:
client.POST("/resource").
Retry().Set(2, time.Second * 2).
Send()
Effortlessly manage multiple endpoints:
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.
Fast Shot supports various types of authentication:
// Bearer Token
builder.Auth().BearerToken("your-bearer-token")
// Basic Authentication
builder.Auth().BasicAuth("username", "password")
// Custom Authentication
builder.Auth().Set("custom-authentication-header")
Add your own headers and cookies effortlessly:
// 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"})
Control every aspect of the HTTP client:
// 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")
Your contributions are always welcome! Feel free to create pull requests, submit issues, or contribute in any other way.