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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?