Resty
HTTP and REST client for Go with a fluent API, retries, automatic JSON and middleware.
Official Documentation ↗resty v2.13+ / Go 1.20+. Check the official docs for the latest API surface.Installation
go get github.com/go-resty/resty/v2Methods
No methods match this filter.
Overview
Resty is a REST client for Go with a fluent builder, automatic JSON serialization, retries and middleware. It reduces boilerplate around net/http for API consumption.
Core Methods
Create a client, use R to start a request chain, set headers, query and body, and call a verb. SetResult and SetError decode bodies, and middleware runs around each request.
Usage Notes
Configure base URL, timeout and retries once on the client, decode into typed results, and attach auth centrally. Keep request chains short and readable.
Common Pitfalls
Unbounded retries on non-idempotent calls duplicate writes. Not setting a timeout risks hanging requests. Sharing a client is safe, but mutating its configuration concurrently is not.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/go-resty/resty@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:10.613Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If there was a response from the server, the original error will be wrapped in *resty.ResponseError which contains the last response received. (https://cdn.jsdelivr.net/gh/go-resty/resty@latest/README.md)
- Therefore, the above setup will result in resty retrying requests with non-nil errors up to 3 times, with the delay increasing after each attempt. (https://cdn.jsdelivr.net/gh/go-resty/resty@latest/README.md)
- It’s important to note that when you specify conditions using AddRetryCondition, it will override the default retry behavior, which retries on errors encountered during the request. (https://cdn.jsdelivr.net/gh/go-resty/resty@latest/README.md)
FAQ
- How do retries work?
- resty can retry on configured conditions such as connection errors or specific status codes, with optional backoff. Retries should be limited to idempotent requests.
- How is JSON handled?
- Setting a body serializes Go values to JSON when appropriate, and SetResult or SetError decodes responses into provided pointers automatically.
- How do I add auth to every request?
- Use middleware or a client-level header so tokens are attached centrally, and refresh them in the request middleware when they expire.
Report a problem with this API docOpens a pre-filled issue on GitHub.