RequestOpts.WithMethod
Overview
WithMethod sets method on opts (helper for Fetch).
Part of the client package — Node.js analog: axios, fetch.
Method on RequestOpts — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func WithMethod(method string) *RequestOptsCompare: 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{}.WithMethod("POST")Example
go
import "github.com/sahilkhaire/gox/client"
opts := client.RequestOpts{}.WithMethod("POST")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)