# requests **Repository Path**: Freshman_Qin/requests ## Basic Information - **Project Name**: requests - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-18 - **Last Updated**: 2025-07-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Requests [](https://godoc.org/github.com/carlmjohnson/requests) [](https://goreportcard.com/report/github.com/carlmjohnson/requests) [](https://coveralls.io/github/earthboundkid/requests) [](https://github.com/avelino/awesome-go)  ## _HTTP requests for Gophers._ **The problem**: Go's net/http is powerful and versatile, but using it correctly for client requests can be extremely verbose. **The solution**: The requests.Builder type is a convenient way to build, send, and handle HTTP requests. Builder has a fluent API with methods returning a pointer to the same struct, which allows for declaratively describing a request by method chaining. Requests also comes with tools for building custom http transports, include a request recorder and replayer for testing. *[See this note on the canonical project URL.](https://gist.github.com/earthboundkid/8915002ae0e531cecdfc58bc6453ac80)* ## Features - Simplifies HTTP client usage compared to net/http - Can't forget to close response body - Checks status codes by default - Supports context.Context - JSON serialization and deserialization helpers - Easily manipulate URLs and query parameters - Request recording and replaying for tests - Customizable transports and validators that are compatible with the standard library and third party libraries - No third party dependencies - Good test coverage ## Examples ### Simple GET into a string
| code with net/http | code with requests |
|---|---|
| ```go req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://example.com", nil) if err != nil { // ... } res, err := http.DefaultClient.Do(req) if err != nil { // ... } defer res.Body.Close() b, err := io.ReadAll(res.Body) if err != nil { // ... } s := string(b) ``` | ```go var s string err := requests. URL("http://example.com"). ToString(&s). Fetch(ctx) ``` |
| 11+ lines | 5 lines |
| code with net/http | code with requests |
|---|---|
| ```go body := bytes.NewReader(([]byte(`hello, world`)) req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://postman-echo.com/post", body) if err != nil { // ... } req.Header.Set("Content-Type", "text/plain") res, err := http.DefaultClient.Do(req) if err != nil { // ... } defer res.Body.Close() _, err := io.ReadAll(res.Body) if err != nil { // ... } ``` | ```go err := requests. URL("https://postman-echo.com/post"). BodyBytes([]byte(`hello, world`)). ContentType("text/plain"). Fetch(ctx) ``` |
| 12+ lines | 5 lines |
| code with net/http | code with requests |
|---|---|
| ```go var post placeholder u, err := url.Parse("https://jsonplaceholder.typicode.com") if err != nil { // ... } u.Path = fmt.Sprintf("/posts/%d", 1) req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) if err != nil { // ... } res, err := http.DefaultClient.Do(req) if err != nil { // ... } defer res.Body.Close() b, err := io.ReadAll(res.Body) if err != nil { // ... } err := json.Unmarshal(b, &post) if err != nil { // ... } ``` | ```go var post placeholder err := requests. URL("https://jsonplaceholder.typicode.com"). Pathf("/posts/%d", 1). ToJSON(&post). Fetch(ctx) ``` |
| 18+ lines | 7 lines |