Convert Figma logo to code with AI

go-resty logoresty

Simple HTTP, REST, and SSE client library for Go

10,684
733
10,684
5

Top Related Projects

An enhanced HTTP client for Go

GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )

A Go "clone" of the great and famous Requests library

4,430

Simple Go HTTP client with Black Magic

1,694

A Go HTTP client library for creating and sending API requests

Plugin-driven, extensible HTTP client toolkit for Go

Quick Overview

go-resty/resty is a simple HTTP and REST client library for Go (golang). It provides an elegant and fluent API for making HTTP requests, handling responses, and managing various aspects of HTTP communication. Resty is designed to be easy to use while offering powerful features for complex scenarios.

Pros

  • Simple and intuitive API for making HTTP requests
  • Extensive feature set, including automatic retries, timeouts, and proxy support
  • Built-in support for JSON, XML, and form data
  • Highly customizable and extensible

Cons

  • May be overkill for very simple HTTP requests
  • Learning curve for advanced features
  • Dependency on external library (which some projects may want to avoid)

Code Examples

  1. Basic GET request:
resp, err := resty.New().R().Get("https://api.example.com/users")
if err != nil {
    log.Fatal(err)
}
fmt.Println(resp.String())
  1. POST request with JSON payload:
client := resty.New()
resp, err := client.R().
    SetHeader("Content-Type", "application/json").
    SetBody(map[string]interface{}{"name": "John", "age": 30}).
    Post("https://api.example.com/users")
if err != nil {
    log.Fatal(err)
}
fmt.Println(resp.StatusCode())
  1. Request with authentication and automatic retries:
client := resty.New().
    SetRetryCount(3).
    SetRetryWaitTime(5 * time.Second).
    SetAuthToken("your-auth-token")

resp, err := client.R().
    SetQueryParam("page", "1").
    Get("https://api.example.com/protected-resource")
if err != nil {
    log.Fatal(err)
}
fmt.Println(resp.String())

Getting Started

To start using go-resty/resty in your Go project:

  1. Install the library:

    go get github.com/go-resty/resty/v2
    
  2. Import and use in your code:

    import "github.com/go-resty/resty/v2"
    
    func main() {
        client := resty.New()
        resp, err := client.R().Get("https://api.example.com")
        // Handle response and error
    }
    

Competitor Comparisons

An enhanced HTTP client for Go

Pros of Heimdall

  • Built-in circuit breaker functionality for improved fault tolerance
  • Supports multiple retry mechanisms (constant, exponential backoff)
  • Provides detailed metrics and instrumentation out of the box

Cons of Heimdall

  • Less extensive documentation compared to Resty
  • Fewer built-in features for request/response manipulation
  • Smaller community and fewer third-party extensions

Code Comparison

Heimdall:

client := heimdall.NewHTTPClient(timeout)
response, err := client.Get("https://example.com", nil)

Resty:

client := resty.New()
resp, err := client.R().Get("https://example.com")

Both libraries offer simple ways to make HTTP requests, but Resty provides a more fluent API for chaining methods. Heimdall focuses on resilience and fault tolerance, while Resty offers more flexibility in request/response handling.

Heimdall is better suited for applications requiring robust error handling and circuit breaking, whereas Resty excels in scenarios needing extensive request customization and response parsing.

GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )

Pros of gorequest

  • Simpler API with a more fluent interface
  • Built-in support for multipart file uploads
  • Easier to set and use cookies

Cons of gorequest

  • Less actively maintained (last commit over 3 years ago)
  • Fewer features and customization options
  • Limited support for advanced HTTP functionalities

Code Comparison

gorequest:

resp, body, errs := gorequest.New().
    Post("http://example.com").
    Send(map[string]string{"name": "John"}).
    End()

resty:

resp, err := resty.New().R().
    SetBody(map[string]string{"name": "John"}).
    Post("http://example.com")

Both libraries provide a clean and intuitive way to make HTTP requests, but resty offers more advanced features and better maintenance. gorequest has a slightly more concise syntax for simple requests, while resty provides greater flexibility and control over the request/response cycle.

resty is generally considered more robust and feature-rich, with better performance and a more active development community. It offers features like automatic retries, backoff mechanisms, and extensive middleware support.

gorequest, while simpler to use for basic tasks, lacks some of the advanced capabilities and ongoing support that resty provides. However, it may still be suitable for smaller projects or those requiring a more straightforward API.

A Go "clone" of the great and famous Requests library

Pros of grequests

  • Simpler API with fewer methods, making it easier to learn and use for basic HTTP requests
  • Supports both synchronous and asynchronous requests out of the box
  • Closer to Python's requests library syntax, which may be familiar to developers coming from Python

Cons of grequests

  • Less actively maintained compared to resty (fewer recent updates and contributions)
  • Fewer advanced features and customization options
  • Limited middleware support for request/response modification

Code Comparison

grequests:

resp, err := grequests.Get("http://example.com", nil)
if err != nil {
    log.Fatalln("Unable to make request: ", err)
}
fmt.Println(resp.String())

resty:

resp, err := resty.New().R().Get("http://example.com")
if err != nil {
    log.Fatalln("Unable to make request: ", err)
}
fmt.Println(string(resp.Body()))

Both libraries offer simple ways to make HTTP requests, but resty provides more advanced features and customization options. grequests may be preferred for simpler use cases or by developers familiar with Python's requests library, while resty is better suited for more complex scenarios and offers better performance and maintainability in the long run.

4,430

Simple Go HTTP client with Black Magic

Pros of req

  • Simpler API with fewer concepts to learn
  • Built-in support for HTTP/2 and HTTP/3
  • More efficient memory usage due to reusable buffer pool

Cons of req

  • Less extensive documentation compared to resty
  • Fewer third-party extensions and integrations
  • Not as widely adopted in the Go community

Code Comparison

req:

client := req.C().EnableDebugLog()
resp, err := client.R().
    SetBody(map[string]interface{}{"foo": "bar"}).
    Post("https://api.example.com/data")

resty:

client := resty.New()
resp, err := client.R().
    SetBody(map[string]interface{}{"foo": "bar"}).
    Post("https://api.example.com/data")

Both libraries offer similar functionality for making HTTP requests, but req provides a more streamlined API with built-in support for newer HTTP protocols. resty, on the other hand, has a larger ecosystem and more extensive documentation. The choice between the two depends on specific project requirements and personal preferences.

1,694

A Go HTTP client library for creating and sending API requests

Pros of Sling

  • Lightweight and focused on simplicity
  • Built-in support for OAuth1a authentication
  • Easier to set up and use for basic API requests

Cons of Sling

  • Less feature-rich compared to Resty
  • Limited middleware and plugin support
  • Fewer options for customizing request behavior

Code Comparison

Sling:

sling := sling.New().Base("https://api.example.com/")
req, err := sling.New().Get("users").QueryStruct(params).Request()

Resty:

client := resty.New()
resp, err := client.R().
    SetQueryParams(params).
    Get("https://api.example.com/users")

Key Differences

  • Resty offers more advanced features like automatic retries, request tracing, and extensive middleware support
  • Sling focuses on simplicity and ease of use for basic API interactions
  • Resty provides a more fluent API with chaining methods, while Sling uses a more traditional approach
  • Resty has built-in support for various authentication methods, while Sling primarily supports OAuth1a out of the box

Use Cases

  • Choose Sling for simpler projects with basic API requirements or when working with OAuth1a APIs
  • Opt for Resty in larger projects that require more advanced features, customization options, and extensive middleware support

Plugin-driven, extensible HTTP client toolkit for Go

Pros of gentleman

  • More modular and composable architecture, allowing for greater flexibility
  • Built-in support for middleware and plugins
  • Extensive testing capabilities, including mocking and stubbing

Cons of gentleman

  • Less actively maintained compared to resty
  • Smaller community and fewer third-party extensions
  • Steeper learning curve due to its more complex architecture

Code Comparison

gentleman:

cli := gentleman.New()
cli.URL("https://api.example.com")
cli.Use(plugin.NewRequestLogger())

res, err := cli.Request().
    Method("GET").
    Path("/users").
    Send()

resty:

client := resty.New()
resp, err := client.R().
    EnableTrace().
    Get("https://api.example.com/users")

Both libraries provide a fluent API for making HTTP requests, but gentleman offers more granular control over the request pipeline through its modular design. resty, on the other hand, provides a simpler and more straightforward approach, which may be preferable for less complex use cases.

While gentleman offers more flexibility and extensibility, resty has gained more popularity and has a larger community, which can be beneficial for long-term support and third-party integrations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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. (jeeva@myjeeva.com)

Contributors

Have a look on Contributors page.

License Info

Resty released under MIT LICENSE.

Resty Documentation and website released under Apache-2.0 LICENSE.