RequestOpts.JSONBody
Overview
JSONBody returns RequestOpts with a JSON body.
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 JSONBody(v any) *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{}.JSONBody(map[string]string{"name": "Ada"})Example
go
import "github.com/sahilkhaire/gox/client"
opts := client.RequestOpts{}.JSONBody(map[string]string{"name": "Ada"})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)