Giter VIP home page Giter VIP logo

fast-shot's Introduction

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.

fast-shot's People

Contributors

hugo-andrade avatar kevm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.