opus-domini / fast-shot

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

go get github.com/opus-domini/fast-shot

Quick Start πŸš€

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

Advanced Usage πŸ› οΈ

Fluent API

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

Retry Mechanism

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

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

Out-of-the-Box Support for Client Load Balancing

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.

Authentication

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

Custom Headers and Cookies

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"})

Advanced Configurations

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

Contributing 🀝

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

About

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

License:MIT License


Languages

Language:Go 97.7%Language:Makefile 2.3%