A simple and easy-to-use HTTP request library for Go, inspired by Python's Requests library
Repo sunerpy/requests, read from GitHub 2 d ago. sunerpy has not joined Take My Repo.
sunerpy/requests is a public repo on GitHub by sunerpy. A simple and easy-to-use HTTP request library for Go, inspired by Python's Requests library. It declares the MIT license on GitHub. It is written mainly in Go, has 2 stars and last changed on 2026-04-13. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-22.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
English | 简体中文
Go Requests is a modern, type-safe HTTP client library for Go, inspired by Python's Requests library. It leverages Go 1.18+ generics to provide compile-time type safety and a fluent API for building HTTP requests.
GetJSON[T], PostJSON[T], etc. return Result[T] for automatic response parsingNewGet, NewPost, etc.Result[T] wraps both parsed data and response metadatago get github.com/sunerpy/requests
import "github.com/sunerpy/requests"
// Basic GET request
resp, err := requests.Get("https://api.github.com")
if err != nil {
log.Fatal(err)
}
fmt.Println("Status:", resp.StatusCode)
fmt.Println("Body:", resp.Text())
// GET with query parameters using options
resp, err := requests.Get("https://api.github.com/search/repos",
requests.WithQuery("q", "golang"),
requests.WithQuery("sort", "stars"),
)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
// GetJSON returns Result[T] which wraps both data and response metadata
result, err := requests.GetJSON[User]("https://api.example.com/user/1")
if err != nil {
log.Fatal(err)
}
// Access parsed data
fmt.Printf("User: %+v\n", result.Data())
// Access response metadata
fmt.Printf("Status: %d\n", result.StatusCode())
fmt.Printf("Success: %v\n", result.IsSuccess())
fmt.Printf("Headers: %v\n", result.Headers())
type CreateUser struct {
Name string `json:"name"`
Email string `json:"email"`
}
type UserResponse struct {
ID int `json:"id"`
}
// PostJSON returns Result[T]
result, err := requests.PostJSON[UserResponse](
"https://api.example.com/users",
CreateUser{Name: "John", Email: "john@example.com"},
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created user ID: %d\n", result.Data().ID)
fmt.Printf("Status: %d\n", result.StatusCode())
// Use convenience constructors for common methods
req, err := requests.NewPost("https://api.example.com/users").
WithHeader("X-Custom-Header", "value").
WithQuery("version", "v2").
WithJSON(map[string]string{"name": "John"}).
WithTimeout(10 * time.Second).
Build()
// Or use NewRequestBuilder for any method
req, err := requests.NewRequestBuilder(requests.MethodPatch, "https://api.example.com/users/1").
WithJSON(map[string]string{"name": "Jane"}).
Build()
// Execute with DoJSON for automatic JSON parsing
result, err := requests.DoJSON[UserResponse](
requests.NewPost("https://api.example.com/users").
WithJSON(CreateUser{Name: "John", Email: "john@example.com"}),
)
// Add headers, query params, auth, etc. using variadic options
resp, err := requests.Get("https://api.example.com/data",
requests.WithHeader("X-Custom-Header", "value"),
requests.WithQuery("page", "1"),
requests.WithBearerToken("my-token"),
requests.WithTimeout(10 * time.Second),
)
session := requests.NewSession().
WithBaseURL("https://api.example.com").
WithTimeout(30 * time.Second).
WithHeader("Authorization", "Bearer token").
WithHTTP2(true).
WithMaxIdleConns(100)
defer session.Close()
// Build request using the new Builder API
req, _ := requests.NewGet("/users").Build()
// Execute with session
resp, err := session.Do(req)
import "context"
// Create a context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
session := requests.NewSession()
defer session.Close()
req, _ := requests.NewGet("https://api.example.com/data").Build()
// Execute with context - respects timeout and cancellation
resp, err := session.DoWithContext(ctx, req)
if err != nil {
if err == context.DeadlineExceeded {
log.Println("Request timed out")
} else if err == context.Canceled {
log.Println("Request was cancelled")
}
return
}
fmt.Println("Response:", resp.Text())
ctx, cancel := context.WithCancel(context.Background())
// Cancel the request after 2 seconds
go func() {
time.Sleep(2 * time.Second)
cancel()
}()
session := requests.NewSession()
defer session.Close()
req, _ := requests.NewGet("https://api.example.com/slow-endpoint").Build()
resp, err := session.DoWithContext(ctx, req)
if err != nil {
// Handle cancellation
log.Printf("Request cancelled: %v", err)
}
session := requests.NewSession().
WithBaseURL("https://api.example.com").
WithTimeout(30 * time.Second).
WithRetry(requests.RetryPolicy{
MaxAttempts: 3,
InitialInterval: 100 * time.Millisecond,
MaxInterval: 5 * time.Second,
Multiplier: 2.0,
RetryIf: func(resp *requests.Response, err error) bool {
if err != nil {
return true // Retry on network errors
}
// Retry on 5xx errors and 429 Too Many Requests
return resp.StatusCode >= 500 || resp.StatusCode == 429
},
})
defer session.Close()
req, _ := requests.NewGet("/users").Build()
resp, err := session.Do(req) // Will automatically retry on failure
// Create a logging middleware
loggingMiddleware := requests.MiddlewareFunc(func(req *requests.Request, next requests.Handler) (*requests.Response, error) {
start := time.Now()
log.Printf("Request: %s %s", req.Method, req.URL)
resp, err := next(req)
duration := time.Since(start)
if resp != nil {
log.Printf("Response: %d in %v", resp.StatusCode, duration)
}
return resp, err
})
// Create session with middleware
session := requests.NewSession().
WithBaseURL("https://api.example.com").
WithMiddleware(loggingMiddleware)
defer session.Close()
req, _ := requests.NewGet("/users").Build()
resp, err := session.Do(req) // Middleware will log request/response
// Logging middleware
loggingMiddleware := requests.MiddlewareFunc(func(req *requests.Request, next requests.Handler) (*requests.Response, error) {
log.Printf("Request: %s %s", req.Method, req.URL)
resp, err := next(req)
if resp != nil {
log.Printf("Response: %d", resp.StatusCode)
}
return resp, err
})
chain := requests.NewMiddlewareChain(loggingMiddleware)
policy := requests.ExponentialRetryPolicy(3, 100*time.Millisecond, 10*time.Second)
executor := requests.NewRetryExecutor(policy)
resp, err := executor.Execute(nil, func() (*requests.Response, error) {
return requests.Get("https://api.example.com/data")
})
hooks := requests.NewHooks()
// Log all requests
hooks.OnRequest(func(req *requests.Request) {
log.Printf("Sending: %s %s", req.Method, req.URL)
})
// Log all responses with duration
hooks.OnResponse(func(req *requests.Request, resp *requests.Response, duration time.Duration) {
log.Printf("Received: %d in %v", resp.StatusCode, duration)
})
// Log errors
hooks.OnError(func(req *requests.Request, err error, duration time.Duration) {
log.Printf("Error: %v", err)
})
import "github.com/sunerpy/requests/url"
upload, err := url.NewFileUpload("file", "/path/to/file.pdf")
if err != nil {
log.Fatal(err)
}
upload.WithProgress(func(uploaded, total int64) {
fmt.Printf("Progress: %d/%d (%.1f%%)\n", uploaded, total, float64(uploaded)/float64(total)*100)
})
import "github.com/sunerpy/requests/codec"
// Register custom codec
type YAMLCodec struct{}
func (c *YAMLCodec) Encode(v any) ([]byte, error) { /* ... */ }
func (c *YAMLCodec) Decode(data []byte, v any) error { /* ... */ }
func (c *YAMLCodec) ContentType() string { return "application/yaml" }
codec.Register("application/yaml", &YAMLCodec{})
requests| Function | Description |
|---|---|
Get(url, opts...) |
Send GET request |
Post(url, body, opts...) |
Send POST request with body |
Put(url, body, opts...) |
Send PUT request with body |
Delete(url, opts...) |
Send DELETE request |
Patch(url, body, opts...) |
Send PATCH request with body |
Head(url, opts...) |
Send HEAD request |
Options(url, opts...) |
Send OPTIONS request |
GetJSON[T](url, opts...) |
GET with JSON parsing, returns (Result[T], error) |
PostJSON[T](url, data, opts...) |
POST JSON, returns (Result[T], error) |
PutJSON[T](url, data, opts...) |
PUT JSON, returns (Result[T], error) |
DeleteJSON[T](url, opts...) |
DELETE with JSON parsing, returns (Result[T], error) |
PatchJSON[T](url, data, opts...) |
PATCH JSON, returns (Result[T], error) |
GetString(url, opts...) |
GET and return body as string |
GetBytes(url, opts...) |
GET and return body as bytes |
DoJSON[T](builder) |
Execute builder and parse JSON response |
NewSession() |
Create new session |
DefaultSession() |
Get the default session |
| Method | Description |
|---|---|
Do(req) |
Execute request |
DoWithContext(ctx, req) |
Execute request with context (supports timeout/cancellation) |
Clone() |
Create a copy of the session |
Close() |
Close the session and release resources |
Clear() |
Reset session to default state |
| Method | Description |
|---|---|
WithBaseURL(url) |
Set base URL for all requests |
WithTimeout(duration) |
Set request timeout |
WithProxy(url) |
Set proxy URL |
WithDNS(servers) |
Set custom DNS servers |
WithHeader(key, value) |
Add default header |
WithHeaders(map) |
Add multiple default headers |
WithBasicAuth(user, pass) |
Set basic authentication |
WithBearerToken(token) |
Set bearer token |
WithHTTP2(enabled) |
Enable/disable HTTP/2 |
WithKeepAlive(enabled) |
Enable/disable keep-alive |
WithMaxIdleConns(n) |
Set max idle connections |
WithIdleTimeout(duration) |
Set idle connection timeout |
WithRetry(policy) |
Set retry policy |
WithMiddleware(m) |
Add middleware |
WithCookieJar(jar) |
Set cookie jar |
| Function | Description |
|---|---|
NewGet(url) |
Create GET request builder |
NewPost(url) |
Create POST request builder |
NewPut(url) |
Create PUT request builder |
NewDeleteBuilder(url) |
Create DELETE request builder |
NewPatch(url) |
Create PATCH request builder |
NewRequestBuilder(method, url) |
Create request builder with any method |
| Method | Description |
|---|---|
Data() |
Get parsed response data of type T |
Response() |
Get underlying Response object |
StatusCode() |
Get HTTP status code |
Headers() |
Get response headers |
IsSuccess() |
Check if status is 2xx |
IsError() |
Check if status is 4xx or 5xx |
Cookies() |
Get response cookies |
| Option | Description |
|---|---|
WithHeader(key, value) |
Add a header |
WithHeaders(map) |
Add multiple headers |
WithQuery(key, value) |
Add a query parameter |
WithQueryParams(map) |
Add multiple query parameters |
WithBasicAuth(user, pass) |
Set basic authentication |
WithBearerToken(token) |
Set bearer token |
WithTimeout(duration) |
Set request timeout |
WithContentType(type) |
Set Content-Type header |
WithContext(ctx) |
Set request context |
WithAccept(type) |
Set Accept header |
sunerpy/requests is a public repo on GitHub by sunerpy. A simple and easy-to-use HTTP request library for Go, inspired by Python's Requests library.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-04-13. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run requests. What is known comes from GitHub. It declares the MIT license on GitHub. Its last change was on 2026-04-13. It has 2 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.