Go Resty

Go Resty is a Go language library for building RESTful API clients. It provides a concise and powerful API that enables developers to easily send HTTP requests and handle responses.

Features

  • Supports GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, and other request methods
  • Simple and chainable settings and request methods
  • Request body can be of type string, []byte, struct, map, slice, and io.Reader
    • Automatically detects Content-Type
    • Uses unbuffered processing for io.Reader
    • Accesses the original *http.Request instance via Request.RawRequest in middleware and request execution
    • Allows multiple reads of the request body through Request.RawRequest.GetBody()
  • Provides more possibilities with the Response object
    • Accesses the response as a []byte array - response.Body(), or as a string - response.String()
    • Retrieves response time response.Time() and received time response.ReceivedAt()
  • Automatically encodes and decodes content types such as JSON and XML
    • Defaults to JSON if Content-Type header and struct/map parameters are not provided
    • Provides options to override JSON encoding/decoding and XML encoding/decoding
  • Simple uploading of one or more files via multipart/form-data
    • Automatically detects the content type of the files
  • Supports backoff retry mechanism and retry condition function references
  • Middleware support for HTTP and REST requests in the Resty client, including Request and Response
  • Supports Request.SetContext
  • Authorization options for BasicAuth and Bearer tokens
  • Sets the request ContentLength value for all requests or specific requests
  • Custom root certificates and client certificates
  • Directly downloads/saves HTTP responses to a file, similar to the curl -o command
  • Request and CookieJar support for cookies
  • Requests based on SRV records instead of the host URL
  • Client settings such as Timeout, RedirectPolicy, Proxy, TLSClientConfig, Transport, etc.
  • Resty design
    • Set and select at the client level, with the option to override at the request level
    • Middleware for requests and responses
    • Allows creation of multiple clients using resty.New() if needed
  • Goroutine safe for concurrency
  • Debug mode - clear and rich log display
  • Gzip - Go automatically handles it, with fallback handling in Resty
  • Compatible with HTTP/2 and HTTP/1.1
  • Bazel support
  • Provides easy mocking for testing Resty

Supported Go Versions

It is recommended to use go1.16 and above.

Starting from version v1.10.0, Resty supports go modules.

From Resty version v2 and higher, it fully supports go modules package publishing. It requires the use of a Go version that understands the /vN suffix imports:

  • 1.9.7+
  • 1.10.3+
  • 1.11+