English | 简体中文
Go Requests is a simple and easy-to-use HTTP request library for Go, inspired by Python's Requests library. It provides an easy-to-understand and use API designed to simplify HTTP requests in Go.
- Easy-to-use HTTP request API
- Supports common HTTP request methods such as GET, POST, PUT, DELETE, etc.
- Automatically handles headers, URL encoding, JSON encoding/decoding, etc.
- Supports HTTP request timeout configuration
- Supports file upload and download
- Supports proxy settings
- Supports DNS server settings
- Supports request redirection and cookie management
Install via Go modules:
go get github.com/sunerpy/requests
package main
import (
"fmt"
"log"
"github.com/sunerpy/requests"
)
func main() {
resp, err := requests.Get("https://api.github.com",nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Response Body:", resp.Text())
}
package main
import (
"fmt"
"log"
"github.com/sunerpy/requests"
)
func main() {
resp, err := requests.Post("https://httpbin.org/post", nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Response JSON:", resp.JSON())
}
package main
import (
"fmt"
"log"
"github.com/sunerpy/requests"
)
func main() {
resp, err := requests.Post("https://httpbin.org/post", nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("Response JSON:", resp.JSON())
}
package main
import (
"fmt"
"log"
"time"
"github.com/sunerpy/requests"
)
func main() {
session := requests.NewSession()
session.SetTimeout(5 * time.Second)
req, err := requests.NewRequest("GET", "https://httpbin.org/get", nil, nil)
if err != nil {
log.Fatal(err)
}
resp, err := session.Do(req)
if err != nil {
log.Fatal(err)
}
fmt.Println("Response:", resp.Text())
}
Initiates a GET request。
url
:The URL of the request。
Initiates a POST request。
url
:The URL of the request。
Creates a new session, allowing you to set default configurations for requests, such as timeouts, proxies, etc.
Sets the timeout for the request.
Parses the response JSON data and returns it.
Returns the text content of the response.
Contributions are welcome! If you're interested in contributing, please follow these steps:
- Fork this repository.
- Make changes in your fork.
- Submit a pull request.
Go Requests is an open-source project licensed under the MIT license.