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, andio.Reader- Automatically detects
Content-Type - Uses unbuffered processing for
io.Reader - Accesses the original
*http.Requestinstance viaRequest.RawRequestin middleware and request execution - Allows multiple reads of the request body through
Request.RawRequest.GetBody()
- Automatically detects
- Provides more possibilities with the Response object
- Accesses the response as a
[]bytearray -response.Body(), or as astring-response.String() - Retrieves response time
response.Time()and received timeresponse.ReceivedAt()
- Accesses the response as a
- Automatically encodes and decodes content types such as
JSONandXML- Defaults to
JSONifContent-Typeheader andstruct/mapparameters are not provided - Provides options to override JSON encoding/decoding and XML encoding/decoding
- Defaults to
- 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
BasicAuthandBearertokens - Sets the request
ContentLengthvalue for all requests or specific requests - Custom root certificates and client certificates
- Directly downloads/saves HTTP responses to a file, similar to the
curl -ocommand - 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/2andHTTP/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+