fastshot

package module
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 15 Imported by: 2

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:

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.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type BalancedBaseURL ΒΆ added in v0.9.0

type BalancedBaseURL struct {
	// contains filtered or unexported fields
}

BalancedBaseURL implements ConfigBaseURL interface and provides load balancing.

func (*BalancedBaseURL) BaseURL ΒΆ added in v0.9.0

func (c *BalancedBaseURL) BaseURL() *url.URL

BaseURL for BalancedBaseURL returns the next base URL in the list.

type BuilderAuth ΒΆ added in v0.9.0

type BuilderAuth[T any] interface {
	Set(value string) *T
	BearerToken(token string) *T
	BasicAuth(username, password string) *T
}

BuilderAuth is the interface that wraps the basic methods for setting HTTP Authentication.

type BuilderCookie ΒΆ added in v0.9.0

type BuilderCookie[T any] interface {
	Add(cookie *http.Cookie) *T
}

BuilderCookie is the interface that wraps the basic methods for setting HTTP Cookies.

type BuilderHeader ΒΆ added in v0.9.0

type BuilderHeader[T any] interface {
	Add(key, value string) *T
	AddAll(headers map[string]string) *T
	Set(key, value string) *T
	SetAll(headers map[string]string) *T
	AddAccept(value string) *T
	AddContentType(value string) *T
	AddUserAgent(value string) *T
}

BuilderHeader is the interface that wraps the basic methods for setting custom HTTP BuilderHeader.

type BuilderHttpClientConfig ΒΆ added in v0.9.0

type BuilderHttpClientConfig[T any] interface {
	SetCustomHttpClient(httpClient HttpClientComponent) *T
	SetCustomTransport(transport http.RoundTripper) *T
	SetTimeout(duration time.Duration) *T
	SetFollowRedirects(follow bool) *T
	SetProxy(proxyURL string) *T
}

BuilderHttpClientConfig is the interface that wraps the basic methods for setting HTTP ClientConfig configuration.

type BuilderRequestBody ΒΆ added in v0.9.0

type BuilderRequestBody[T any] interface {
	AsReader(body io.Reader) *T
	AsString(body string) *T
	AsJSON(obj interface{}) *T
}

BuilderRequestBody is the interface that wraps the basic methods for setting HTTP BuilderRequestBody.

type BuilderRequestContext ΒΆ added in v0.9.0

type BuilderRequestContext[T any] interface {
	Set(ctx context.Context) *T
}

BuilderRequestContext is the interface that wraps the basic methods for setting HTTP BuilderRequestContext.

type BuilderRequestQuery ΒΆ added in v0.9.0

type BuilderRequestQuery[T any] interface {
	AddParam(param, value string) *T
	AddParams(params map[string]string) *T
	SetParam(param, value string) *T
	SetParams(params map[string]string) *T
	SetRawString(query string) *T
}

BuilderRequestQuery is the interface that wraps the basic methods for setting HTTP BuilderRequestQuery.

type BuilderRequestRetry ΒΆ added in v0.9.0

type BuilderRequestRetry[T any] interface {
	Set(retries int, retryInterval time.Duration) *T
}

BuilderRequestRetry is the interface that wraps the basic methods for setting HTTP BuilderRequestRetry.

type Client ΒΆ

type Client interface {
	ClientConfig
	ClientHttpMethods
}

type ClientAuthBuilder ΒΆ

type ClientAuthBuilder struct {
	// contains filtered or unexported fields
}

ClientAuthBuilder allows for setting authentication configurations.

func (*ClientAuthBuilder) BasicAuth ΒΆ

func (b *ClientAuthBuilder) BasicAuth(username, password string) *ClientBuilder

BasicAuth sets the Authorization header for Basic authentication.

func (*ClientAuthBuilder) BearerToken ΒΆ

func (b *ClientAuthBuilder) BearerToken(token string) *ClientBuilder

BearerToken sets the Authorization header for Bearer token authentication.

func (*ClientAuthBuilder) Set ΒΆ

func (b *ClientAuthBuilder) Set(value string) *ClientBuilder

Set sets the Authorization header for custom authentication.

type ClientBuilder ΒΆ

type ClientBuilder struct {
	// contains filtered or unexported fields
}

ClientBuilder serves as the main entry point for configuring HTTP clients.

func NewClient ΒΆ

func NewClient(baseURL string) *ClientBuilder

NewClient initializes a new ClientBuilder with a given baseURL.

func NewClientLoadBalancer ΒΆ added in v0.9.0

func NewClientLoadBalancer(baseURLs []string) *ClientBuilder

NewClientLoadBalancer initializes a new ClientBuilder with a given baseURLs.

func (*ClientBuilder) Auth ΒΆ

func (b *ClientBuilder) Auth() *ClientAuthBuilder

Auth BuilderAuth returns a new ClientAuthBuilder for setting authentication options.

func (*ClientBuilder) Build ΒΆ

func (b *ClientBuilder) Build() ClientHttpMethods

Build finalizes the ClientBuilder configurations and returns a new ClientConfig.

func (*ClientBuilder) Config ΒΆ

func (b *ClientBuilder) Config() *ClientConfigBuilder

Config returns a new ClientConfigBuilder for setting custom client configurations.

func (*ClientBuilder) Cookie ΒΆ

func (b *ClientBuilder) Cookie() *ClientCookieBuilder

BuilderCookie returns a new ClientCookieBuilder for setting custom HTTP Cookies.

func (*ClientBuilder) Header ΒΆ

func (b *ClientBuilder) Header() *ClientHeaderBuilder

BuilderHeader returns a new ClientHeaderBuilder for setting custom HTTP BuilderHeader.

type ClientConfig ΒΆ added in v0.7.0

type ClientConfig interface {
	ConfigHttpClient
	HttpHeader() *http.Header
	SetHttpCookie(cookie *http.Cookie)
	HttpCookies() []*http.Cookie
	SetValidation(validation error)
	Validations() []error
	ConfigBaseURL
}

type ClientConfigBase ΒΆ added in v0.9.0

type ClientConfigBase struct {
	ConfigBaseURL
	// contains filtered or unexported fields
}

ClientConfigBase serves as the main entry point for configuring HTTP clients.

func (*ClientConfigBase) CONNECT ΒΆ added in v0.9.0

func (c *ClientConfigBase) CONNECT(path string) *RequestBuilder

CONNECT is a shortcut for NewRequest(c, method.CONNECT, path).

func (*ClientConfigBase) DELETE ΒΆ added in v0.9.0

func (c *ClientConfigBase) DELETE(path string) *RequestBuilder

DELETE is a shortcut for NewRequest(c, method.DELETE, path).

func (*ClientConfigBase) GET ΒΆ added in v0.9.0

func (c *ClientConfigBase) GET(path string) *RequestBuilder

GET is a shortcut for NewRequest(c, method.GET, path).

func (*ClientConfigBase) HEAD ΒΆ added in v0.9.0

func (c *ClientConfigBase) HEAD(path string) *RequestBuilder

HEAD is a shortcut for NewRequest(c, method.HEAD, path).

func (*ClientConfigBase) HttpClient ΒΆ added in v0.9.0

func (c *ClientConfigBase) HttpClient() HttpClientComponent

HttpClient for ClientConfigBase returns the HTTP client.

func (*ClientConfigBase) HttpCookies ΒΆ added in v0.9.0

func (c *ClientConfigBase) HttpCookies() []*http.Cookie

HttpCookies for ClientConfigBase returns the HTTP cookies.

func (*ClientConfigBase) HttpHeader ΒΆ added in v0.9.0

func (c *ClientConfigBase) HttpHeader() *http.Header

HttpHeader for ClientConfigBase returns the HTTP header.

func (*ClientConfigBase) OPTIONS ΒΆ added in v0.9.0

func (c *ClientConfigBase) OPTIONS(path string) *RequestBuilder

OPTIONS is a shortcut for NewRequest(c, method.OPTIONS, path).

func (*ClientConfigBase) PATCH ΒΆ added in v0.9.0

func (c *ClientConfigBase) PATCH(path string) *RequestBuilder

PATCH is a shortcut for NewRequest(c, method.PATCH, path).

func (*ClientConfigBase) POST ΒΆ added in v0.9.0

func (c *ClientConfigBase) POST(path string) *RequestBuilder

POST is a shortcut for NewRequest(c, method.POST, path).

func (*ClientConfigBase) PUT ΒΆ added in v0.9.0

func (c *ClientConfigBase) PUT(path string) *RequestBuilder

PUT is a shortcut for NewRequest(c, method.PUT, path).

func (*ClientConfigBase) SetHttpClient ΒΆ added in v0.10.0

func (c *ClientConfigBase) SetHttpClient(httpClient HttpClientComponent)

SetHttpClient for ClientConfigBase sets the HttpClientComponent.

func (*ClientConfigBase) SetHttpCookie ΒΆ added in v0.9.0

func (c *ClientConfigBase) SetHttpCookie(cookie *http.Cookie)

SetHttpCookie for ClientConfigBase sets the HTTP cookie.

func (*ClientConfigBase) SetValidation ΒΆ added in v0.9.0

func (c *ClientConfigBase) SetValidation(validations error)

SetValidation for ClientConfigBase sets the validation.

func (*ClientConfigBase) TRACE ΒΆ added in v0.9.0

func (c *ClientConfigBase) TRACE(path string) *RequestBuilder

TRACE is a shortcut for NewRequest(c, method.TRACE, path).

func (*ClientConfigBase) Validations ΒΆ added in v0.9.0

func (c *ClientConfigBase) Validations() []error

Validations for ClientConfigBase returns the validations.

type ClientConfigBuilder ΒΆ

type ClientConfigBuilder struct {
	// contains filtered or unexported fields
}

ClientConfigBuilder allows for setting other client configurations.

func (*ClientConfigBuilder) SetCustomHttpClient ΒΆ added in v0.10.0

func (b *ClientConfigBuilder) SetCustomHttpClient(httpClient HttpClientComponent) *ClientBuilder

SetCustomHttpClient sets the underlying raw client

func (*ClientConfigBuilder) SetCustomTransport ΒΆ

func (b *ClientConfigBuilder) SetCustomTransport(transport http.RoundTripper) *ClientBuilder

SetCustomTransport sets custom transport for the HTTP client.

func (*ClientConfigBuilder) SetFollowRedirects ΒΆ

func (b *ClientConfigBuilder) SetFollowRedirects(follow bool) *ClientBuilder

SetFollowRedirects controls whether the HTTP client should follow redirects.

func (*ClientConfigBuilder) SetProxy ΒΆ added in v0.8.0

func (b *ClientConfigBuilder) SetProxy(proxyURL string) *ClientBuilder

SetProxy sets the proxy URL for the HTTP client.

func (*ClientConfigBuilder) SetTimeout ΒΆ

func (b *ClientConfigBuilder) SetTimeout(duration time.Duration) *ClientBuilder

SetTimeout sets the timeout for the HTTP client.

type ClientCookieBuilder ΒΆ

type ClientCookieBuilder struct {
	// contains filtered or unexported fields
}

ClientCookieBuilder allows for setting custom HTTP Cookies.

func (*ClientCookieBuilder) Add ΒΆ

func (b *ClientCookieBuilder) Add(cookie *http.Cookie) *ClientBuilder

Add adds a custom cookie to the HTTP client.

type ClientHeaderBuilder ΒΆ

type ClientHeaderBuilder struct {
	// contains filtered or unexported fields
}

ClientHeaderBuilder allows for setting custom HTTP BuilderHeader.

func (*ClientHeaderBuilder) Add ΒΆ

func (b *ClientHeaderBuilder) Add(key, value string) *ClientBuilder

Add adds a custom header to the HTTP client. If header already exists, it will be appended.

func (*ClientHeaderBuilder) AddAccept ΒΆ

func (b *ClientHeaderBuilder) AddAccept(value string) *ClientBuilder

AddAccept sets the Accept header. If header already exists, it will be appended.

func (*ClientHeaderBuilder) AddAll ΒΆ added in v0.6.0

func (b *ClientHeaderBuilder) AddAll(headers map[string]string) *ClientBuilder

AddAll adds multiple custom headers to the HTTP client. If header already exists, it will be appended.

func (*ClientHeaderBuilder) AddContentType ΒΆ

func (b *ClientHeaderBuilder) AddContentType(value string) *ClientBuilder

AddContentType sets the Content-Type header. If header already exists, it will be appended.

func (*ClientHeaderBuilder) AddUserAgent ΒΆ

func (b *ClientHeaderBuilder) AddUserAgent(value string) *ClientBuilder

AddUserAgent sets the User-Agent header. If header already exists, it will be appended.

func (*ClientHeaderBuilder) Set ΒΆ

func (b *ClientHeaderBuilder) Set(key, value string) *ClientBuilder

Set sets a custom header to the HTTP client. If header already exists, it will be overwritten.

func (*ClientHeaderBuilder) SetAll ΒΆ added in v0.6.0

func (b *ClientHeaderBuilder) SetAll(headers map[string]string) *ClientBuilder

SetAll sets multiple custom headers to the HTTP client. If header already exists, it will be overwritten.

type ClientHttpMethods ΒΆ added in v0.9.0

type ClientHttpMethods interface {
	GET(path string) *RequestBuilder
	POST(path string) *RequestBuilder
	PUT(path string) *RequestBuilder
	DELETE(path string) *RequestBuilder
	PATCH(path string) *RequestBuilder
	HEAD(path string) *RequestBuilder
	CONNECT(path string) *RequestBuilder
	OPTIONS(path string) *RequestBuilder
	TRACE(path string) *RequestBuilder
}

func DefaultClient ΒΆ

func DefaultClient(baseURL string) ClientHttpMethods

DefaultClient initializes a new default ClientConfig with a given baseURL.

func DefaultClientLoadBalancer ΒΆ added in v0.9.0

func DefaultClientLoadBalancer(baseURLs []string) ClientHttpMethods

DefaultClientLoadBalancer initializes a new default ClientConfig with a given baseURLs.

type ConfigBaseURL ΒΆ added in v0.9.0

type ConfigBaseURL interface {
	BaseURL() *url.URL
}

type ConfigHttpClient ΒΆ added in v0.10.0

type ConfigHttpClient interface {
	SetHttpClient(httpClient HttpClientComponent)
	HttpClient() HttpClientComponent
}

type DefaultBaseURL ΒΆ added in v0.9.0

type DefaultBaseURL struct {
	// contains filtered or unexported fields
}

DefaultBaseURL implements ConfigBaseURL interface and provides a single base URL.

func (*DefaultBaseURL) BaseURL ΒΆ added in v0.9.0

func (c *DefaultBaseURL) BaseURL() *url.URL

BaseURL for DefaultBaseURL returns the base URL.

type DefaultHttpClient ΒΆ added in v0.10.0

type DefaultHttpClient struct {
	// contains filtered or unexported fields
}

DefaultHttpClient implements HttpClientComponent interface and provides a default HTTP client.

func (*DefaultHttpClient) Do ΒΆ added in v0.10.0

func (c *DefaultHttpClient) Do(req *http.Request) (*http.Response, error)

Do will execute the *http.Client Do method

func (*DefaultHttpClient) SetCheckRedirect ΒΆ added in v0.10.0

func (c *DefaultHttpClient) SetCheckRedirect(f func(*http.Request, []*http.Request) error)

SetCheckRedirect sets the CheckRedirect field on the underlying http.Client type

func (*DefaultHttpClient) SetTimeout ΒΆ added in v0.10.0

func (c *DefaultHttpClient) SetTimeout(duration time.Duration)

SetTimeout sets the Timeout field on the underlying http.Client type

func (*DefaultHttpClient) SetTransport ΒΆ added in v0.10.0

func (c *DefaultHttpClient) SetTransport(transport http.RoundTripper)

SetTransport sets the Transport field on the underlying http.Client type

func (*DefaultHttpClient) Timeout ΒΆ added in v0.10.0

func (c *DefaultHttpClient) Timeout() time.Duration

Timeout will return the underlying timeout value

func (*DefaultHttpClient) Transport ΒΆ added in v0.10.0

func (c *DefaultHttpClient) Transport() http.RoundTripper

Transport will return the underlying transport type

type HttpClientComponent ΒΆ added in v0.10.0

type HttpClientComponent interface {
	Do(*http.Request) (*http.Response, error)
	SetTransport(http.RoundTripper)
	Transport() http.RoundTripper
	SetTimeout(time.Duration)
	Timeout() time.Duration
	SetCheckRedirect(func(*http.Request, []*http.Request) error)
}

type Request ΒΆ

type Request struct {
	// contains filtered or unexported fields
}

type RequestAuthBuilder ΒΆ added in v0.7.0

type RequestAuthBuilder struct {
	// contains filtered or unexported fields
}

RequestAuthBuilder allows for setting authentication configurations.

func (*RequestAuthBuilder) BasicAuth ΒΆ added in v0.7.0

func (b *RequestAuthBuilder) BasicAuth(username, password string) *RequestBuilder

BasicAuth sets the Authorization header for Basic authentication.

func (*RequestAuthBuilder) BearerToken ΒΆ added in v0.7.0

func (b *RequestAuthBuilder) BearerToken(token string) *RequestBuilder

BearerToken sets the Authorization header for Bearer token authentication.

func (*RequestAuthBuilder) Set ΒΆ added in v0.7.0

func (b *RequestAuthBuilder) Set(value string) *RequestBuilder

Set sets the Authorization header for custom authentication.

type RequestBodyBuilder ΒΆ added in v0.6.0

type RequestBodyBuilder struct {
	// contains filtered or unexported fields
}

RequestBodyBuilder serves as the main entry point for configuring BuilderRequestBody.

func (*RequestBodyBuilder) AsJSON ΒΆ added in v0.6.0

func (b *RequestBodyBuilder) AsJSON(obj interface{}) *RequestBuilder

AsJSON sets the body as JSON.

func (*RequestBodyBuilder) AsReader ΒΆ added in v0.6.0

func (b *RequestBodyBuilder) AsReader(body io.Reader) *RequestBuilder

AsReader sets the body as IO Reader.

func (*RequestBodyBuilder) AsString ΒΆ added in v0.6.0

func (b *RequestBodyBuilder) AsString(body string) *RequestBuilder

AsString sets the body as string.

type RequestBuilder ΒΆ added in v0.6.0

type RequestBuilder struct {
	// contains filtered or unexported fields
}

func (*RequestBuilder) Auth ΒΆ added in v0.7.0

BuilderAuth returns a new ClientAuthBuilder for setting authentication options.

func (*RequestBuilder) Body ΒΆ added in v0.6.0

Body returns a new RequestBodyBuilder for setting custom HTTP Body's.

func (*RequestBuilder) Context ΒΆ added in v0.6.0

func (b *RequestBuilder) Context() *RequestContextBuilder

Context returns a new RequestContextBuilder for setting custom Context.

func (*RequestBuilder) Cookie ΒΆ added in v0.6.0

func (b *RequestBuilder) Cookie() *RequestCookieBuilder

BuilderCookie returns a new RequestCookieBuilder for setting custom HTTP Cookies.

func (*RequestBuilder) Header ΒΆ added in v0.6.0

func (b *RequestBuilder) Header() *RequestHeaderBuilder

BuilderHeader returns a new RequestHeaderBuilder for setting custom HTTP BuilderHeader.

func (*RequestBuilder) Query ΒΆ added in v0.6.0

func (b *RequestBuilder) Query() *RequestQueryBuilder

Query returns a new RequestQueryBuilder for setting query parameters.

func (*RequestBuilder) Retry ΒΆ added in v0.6.0

func (b *RequestBuilder) Retry() *RequestRetryBuilder

Retry returns a new RequestRetryBuilder for setting custom HTTP Cookies.

func (*RequestBuilder) Send ΒΆ added in v0.6.0

func (b *RequestBuilder) Send() (Response, error)

type RequestContextBuilder ΒΆ added in v0.6.0

type RequestContextBuilder struct {
	// contains filtered or unexported fields
}

RequestContextBuilder serves as the main entry point for configuring Request Context.

func (*RequestContextBuilder) Set ΒΆ added in v0.6.0

Set sets the Context.

type RequestCookieBuilder ΒΆ added in v0.6.0

type RequestCookieBuilder struct {
	// contains filtered or unexported fields
}

RequestCookieBuilder serves as the main entry point for configuring HTTP Cookies.

func (*RequestCookieBuilder) Add ΒΆ added in v0.6.0

Add adds a custom cookie to the HTTP client.

type RequestHeaderBuilder ΒΆ added in v0.6.0

type RequestHeaderBuilder struct {
	// contains filtered or unexported fields
}

RequestHeaderBuilder is a builder for setting custom HTTP BuilderHeader.

func (*RequestHeaderBuilder) Add ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) Add(key, value string) *RequestBuilder

Add adds a custom header to the HTTP request. If header already exists, it will be appended.

func (*RequestHeaderBuilder) AddAccept ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) AddAccept(value string) *RequestBuilder

AddAccept sets the Accept header. If header already exists, it will be appended.

func (*RequestHeaderBuilder) AddAll ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) AddAll(headers map[string]string) *RequestBuilder

AddAll adds custom headers to the HTTP request. If header already exists, it will be appended.

func (*RequestHeaderBuilder) AddContentType ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) AddContentType(value string) *RequestBuilder

AddContentType sets the Content-Type header. If header already exists, it will be appended.

func (*RequestHeaderBuilder) AddUserAgent ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) AddUserAgent(value string) *RequestBuilder

AddUserAgent sets the User-Agent header. If header already exists, it will be appended.

func (*RequestHeaderBuilder) Set ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) Set(key, value string) *RequestBuilder

Set sets a custom header to the HTTP request. If header already exists, it will be overwritten.

func (*RequestHeaderBuilder) SetAll ΒΆ added in v0.6.0

func (b *RequestHeaderBuilder) SetAll(headers map[string]string) *RequestBuilder

SetAll sets custom headers to the HTTP request. If header already exists, it will be overwritten.

type RequestQueryBuilder ΒΆ added in v0.6.0

type RequestQueryBuilder struct {
	// contains filtered or unexported fields
}

RequestQueryBuilder serves as the main entry point for configuring BuilderRequestQuery.

func (*RequestQueryBuilder) AddParam ΒΆ added in v0.6.0

func (b *RequestQueryBuilder) AddParam(param, value string) *RequestBuilder

AddParam adds a query parameter to the HTTP request. If parameter already exists, it will be appended.

func (*RequestQueryBuilder) AddParams ΒΆ added in v0.6.0

func (b *RequestQueryBuilder) AddParams(params map[string]string) *RequestBuilder

AddParams adds multiple query parameters to the HTTP request. If parameter already exists, it will be appended.

func (*RequestQueryBuilder) SetParam ΒΆ added in v0.6.0

func (b *RequestQueryBuilder) SetParam(param, value string) *RequestBuilder

SetParam sets a query parameter to the HTTP request. If parameter already exists, it will be overwritten.

func (*RequestQueryBuilder) SetParams ΒΆ added in v0.6.0

func (b *RequestQueryBuilder) SetParams(params map[string]string) *RequestBuilder

SetParams sets multiple query parameters to the HTTP request. If parameter already exists, it will be overwritten.

func (*RequestQueryBuilder) SetRawString ΒΆ added in v0.6.0

func (b *RequestQueryBuilder) SetRawString(query string) *RequestBuilder

SetRawString sets query parameters from a raw query string.

type RequestRetryBuilder ΒΆ added in v0.6.0

type RequestRetryBuilder struct {
	// contains filtered or unexported fields
}

RequestRetryBuilder serves as the main entry point for configuring Request retries.

func (*RequestRetryBuilder) Set ΒΆ added in v0.6.0

func (b *RequestRetryBuilder) Set(retries int, retryInterval time.Duration) *RequestBuilder

Set sets the number of retries and the retry interval.

type Response ΒΆ

type Response struct {
	Request     *Request
	RawResponse *http.Response
}

func (*Response) Is1xxInformational ΒΆ

func (r *Response) Is1xxInformational() bool

func (*Response) Is2xxSuccessful ΒΆ

func (r *Response) Is2xxSuccessful() bool

func (*Response) Is3xxRedirection ΒΆ

func (r *Response) Is3xxRedirection() bool

func (*Response) Is4xxClientError ΒΆ

func (r *Response) Is4xxClientError() bool

func (*Response) Is5xxServerError ΒΆ

func (r *Response) Is5xxServerError() bool

func (*Response) IsError ΒΆ

func (r *Response) IsError() bool

func (*Response) RawBody ΒΆ

func (r *Response) RawBody() io.ReadCloser

func (*Response) Status ΒΆ

func (r *Response) Status() string

func (*Response) StatusCode ΒΆ

func (r *Response) StatusCode() int

func (*Response) StatusText ΒΆ added in v0.8.3

func (r *Response) StatusText() string

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL