API Reference

Resty

HTTP and REST client for Go with a fluent API, retries, automatic JSON and middleware.

Official Documentation ↗
CompatibilityThis documentation covers version resty v2.13+ / Go 1.20+. Check the official docs for the latest API surface.

Installation

gogo get github.com/go-resty/resty/v2

Methods

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.

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.