RequestOpts
Overview
RequestOpts configures a single request.
Part of the client package — Node.js analog: axios, fetch.
RequestOpts is a type exported by gox. Methods on this type are documented separately.
Signature
go
type RequestOpts struct {
Method string
URL string
Body io.Reader
Headers http.Header
Query url.Values
JSON any
}Compare: Node.js · Standard Go · gox
js
// Typical axios, fetch pattern in Node.jsgo
resp, err := http.NewRequestWithContext(ctx, method, url, body)
client.Do(req)go
import "github.com/sahilkhaire/gox/client"
opts := &client.RequestOpts{
Method: "GET",
Query: map[string]string{"page": "1"},
Headers: map[string]string{"Accept": "application/json"},
}Example
go
import "github.com/sahilkhaire/gox/client"
opts := &client.RequestOpts{
Method: "GET",
Query: map[string]string{"page": "1"},
Headers: map[string]string{"Accept": "application/json"},
}Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
resp, err := http.NewRequestWithContext(ctx, method, url, body)
client.Do(req)