Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

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: about 1 month ago
JSON representation

Hit your API targets with rapid-fire precision using Go's fastest and simple HTTP Client.

Lists

README

        


Logo fast-shot


A Fluent Go REST Client Library



Go Report Badge
Go Doc Badge
Converage Actions Badge
Codecov Badge
License Badge
Mentioned in Awesome Go


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.

## 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.

## Features 🌟

* Fluent API for HTTP requests
* Extensible authentication
* Customizable HTTP headers
* Query parameter manipulation
* JSON request and response support
* Built-in error handling
* Well-tested

## 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()

// Process response...
}
```

## 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(time.Second * 30).
Build()
```
### Retry Mechanism

Handle transient failures, enhancing the reliability of your HTTP requests:

```go
client.POST("/resource").
Retry().Set(2, time.Second * 2).
Send()
```

### 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")
````

## Contributing 🤝

Your contributions are always welcome! Feel free to create pull requests, submit issues, or contribute in any other way.