Categoryresty.dev/v3
modulepackage
3.0.0-beta.1
Repository: https://github.com/go-resty/resty.git
Documentation: pkg.go.dev

# README

Resty Logo

Simple HTTP, REST, and SSE client library for Go

Resty Build Status Resty Code Coverage Go Report Card Resty GoDoc License Mentioned in Awesome Go

Documentation

Go to https://resty.dev and refer to godoc.

Minimum Go Version

Use go1.21 and above.

Support & Donate

Versioning

Resty releases versions according to Semantic Versioning

  • Resty v3 provides Go Vanity URL resty.dev/v3.
  • Resty v2 migrated away from gopkg.in service, github.com/go-resty/resty/v2.
  • Resty fully adapted to go mod capabilities since v1.10.0 release.
  • Resty v1 series was using gopkg.in to provide versioning. gopkg.in/resty.vX points to appropriate tagged versions; X denotes version series number and it's a stable release for production use. For e.g. gopkg.in/resty.v0.

Contribution

I would welcome your contribution!

  • If you find any improvement or issue you want to fix, feel free to send a pull request.
  • The pull requests must include test cases for feature/fix/enhancement with patch coverage of 100%.
  • I have done my best to bring pretty good coverage. I would request contributors to do the same for their contribution.

I always look forward to hearing feedback, appreciation, and real-world usage stories from Resty users on GitHub Discussions. It means a lot to me.

Creator

Jeevanandam M. ([email protected])

Contributors

Have a look on Contributors page.

License Info

Resty released under MIT LICENSE.

Resty Documentation and website released under Apache-2.0 LICENSE.

# Functions

AutoParseResponseMiddleware method is used to parse the response body automatically based on registered HTTP response `Content-Type` decoder, see [Client.AddContentTypeDecoder]; if [Request.SetResult], [Request.SetError], or [Client.SetError] is used.
CircuitBreaker5xxPolicy is a [CircuitBreakerPolicy] that trips the [CircuitBreaker] if the response status code is 500 or greater.
DebugLogFormatter function formats the given debug log info in human readable format.
DebugLogJSONFormatter function formats the given debug log info in JSON format.
DomainCheckRedirectPolicy method is convenient for defining domain name redirect rules in Resty clients.
FlexibleRedirectPolicy method is convenient for creating several redirect policies for Resty clients.
New method creates a new Resty client.
NewCircuitBreaker method creates a new [CircuitBreaker] with default settings.
NewEventSource method creates a new instance of [EventSource] with default values for Server-Sent Events(SSE) es := NewEventSource().
NewRoundRobin method creates the new Round-Robin(RR) request load balancer instance with given base URLs.
NewSRVWeightedRoundRobin method creates a new Weighted Round-Robin(WRR) load balancer instance with given SRV values.
NewWeightedRoundRobin method creates the new Weighted Round-Robin(WRR) request load balancer instance with given recovery duration and hosts slice.
NewWithClient method creates a new Resty client with given [http.Client].
NewWithDialer method creates a new Resty client with given Local Address to dial from.
NewWithDialerAndTransportSettings method creates a new Resty client with given Local Address to dial from.
NewWithLocalAddr method creates a new Resty client with the given Local Address.
NewWithTransportSettings method creates a new Resty client with provided timeout values.
NoRedirectPolicy is used to disable the redirects in the Resty client resty.SetRedirectPolicy(resty.NoRedirectPolicy()).
PrepareRequestMiddleware method is used to prepare HTTP requests from user provides request values.
SaveToFileResponseMiddleware method used to write HTTP response body into file.

# Constants

Host transition states.
Host transition states.
MethodDelete HTTP method.
MethodGet HTTP method.
MethodHead HTTP method.
MethodOptions HTTP method.
MethodPatch HTTP method.
MethodPost HTTP method.
MethodPut HTTP method.
MethodTrace HTTP method.
Version # of resty.

# Variables

# Structs

CertWatcherOptions allows configuring a watcher that reloads dynamically TLS certs.
CircuitBreaker struct implements a state machine to monitor and manage the states of circuit breakers.
Client struct is used to create a Resty client with client-level settings, these settings apply to all the requests raised from the client.
Host struct used to represent the host information and its weight to load balance the requests.
MultipartField struct represents the multipart field to compose all [io.Reader] capable input for multipart form request.
MultipartFieldProgress struct used to provide multipart field upload progress details via callback function.
Request struct is used to compose and fire individual requests from Resty client.
RequestFeedback struct is used to send the request feedback to load balancing algorithm.
Response struct holds response values of executed requests.
ResponseError is a wrapper that includes the server response with an error.
RoundRobin struct used to implement the Round-Robin(RR) request load balancer algorithm.
SRVWeightedRoundRobin struct used to implement SRV Weighted Round-Robin(RR) algorithm.
TraceInfo struct is used to provide request trace info such as DNS lookup duration, Connection obtain duration, Server processing duration, etc.
TransportSettings struct is used to define custom dialer and transport values for the Resty client.
WeightedRoundRobin struct used to represent the host details for Weighted Round-Robin(WRR) algorithm implementation.

# Interfaces

LoadBalancer is the interface that wraps the HTTP client load-balancing algorithm that returns the "Next" Base URL for the request to target.
Logger interface is to abstract the logging from Resty.

# Type aliases

CircuitBreakerPolicy is a function type that determines whether a response should trip the [CircuitBreaker].
HostStateChangeFunc type provides feedback on host state transitions.
MultipartFieldCallbackFunc function used to transmit live multipart upload progress in bytes count.