Skip to content
Node: axios, fetchgithub.com/sahilkhaire/gox/client

SetDefaultClient

Overview

SetDefaultClient replaces the client used by Fetch.

Part of the client package — Node.js analog: axios, fetch.

Signature

go
func SetDefaultClient(c *Client)

Compare: Node.js · Standard Go · gox

js
// Typical axios, fetch pattern in Node.js
go
resp, err := http.NewRequestWithContext(ctx, method, url, body)
client.Do(req)
go
import "github.com/sahilkhaire/gox/client"

client.SetDefaultClient(c)

Example

go
import "github.com/sahilkhaire/gox/client"

client.SetDefaultClient(c)

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)

Back to client package overview

MIT Licensed · Built for Node.js developers moving to Go