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星跟踪图

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.

主要指标

概览
名称与所有者levigross/grequests
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2015-06-11 16:41:48
推送于2025-06-06 22:33:43
最后一次提交2025-06-06 18:33:41
发布数10
最新版本名称0.10 (发布于 )
第一版名称0.1 (发布于 )
用户参与
星数2.2k
关注者数35
派生数138
提交数119
已启用问题?
问题数63
打开的问题数24
拉请求数23
打开的拉请求数0
关闭的拉请求数25
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?