GRequests

GRequests 为 Go 的 net/http 包提供了一个简洁的封装。它模仿了 Python Requests 库的便利性,同时保持了 Go 的强大功能和安全性。「GRequests provides a clean wrapper around Go's net/http package. It mimics the convenience of the Python Requests library while keeping the power and safety of Go.」  

Github stars Tracking Chart

GRequests

GRequests provides a clean wrapper around Go's net/http package. It mimics the convenience of the Python Requests library while keeping the power and safety of Go.

Join the chat at https://gitter.im/levigross/grequests

Features

  • Simple helpers for every HTTP verb
  • Context aware request functions for easy cancellation
  • RequestOptions for headers, query parameters, proxies, cookies and more
  • Built in support for JSON and XML responses
  • File uploads and convenient download helpers
  • Session type for reusing cookies between requests

Installation

go get github.com/levigross/grequests/v2

Quick start

package main

import (
    "context"
    "log"

    "github.com/levigross/grequests/v2"
)

func main() {
    resp, err := grequests.Get(context.Background(), "https://httpbin.org/get",
        grequests.UserAgent("MyAgent"))
    if err != nil {
        log.Fatal(err)
    }

    var data map[string]any
    if err := resp.JSON(&data); err != nil {
        log.Fatal(err)
    }
    log.Println(data)
}

Uploading a file

fd, _ := grequests.FileUploadFromDisk("testdata/file.txt")
ro := &grequests.RequestOptions{
    Files: fd,
    Data:  map[string]string{"desc": "test"},
}
resp, err := grequests.Post(context.Background(), "https://httpbin.org/post",
    grequests.FromRequestOptions(ro))

Using a session

sess := grequests.NewSession(nil)
_, _ = sess.Get(context.Background(), "https://httpbin.org/cookies/set?one=two", nil)
resp, _ := sess.Get(context.Background(), "https://httpbin.org/cookies", nil)
log.Println(resp.String())

See the documentation for a full list of available options.

License

GRequests is licensed under the Apache License, Version 2.0. See LICENSE for details.

Main metrics

Overview
Name With Ownerlevigross/grequests
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:Apache License 2.0
所有者活动
Created At2015-06-11 16:41:48
Pushed At2025-06-06 22:33:43
Last Commit At2025-06-06 18:33:41
Release Count10
Last Release Name0.10 (Posted on )
First Release Name0.1 (Posted on )
用户参与
Stargazers Count2.2k
Watchers Count35
Fork Count138
Commits Count119
Has Issues Enabled
Issues Count63
Issue Open Count24
Pull Requests Count23
Pull Requests Open Count0
Pull Requests Close Count25
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private