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

Client

Overview

Client is a reusable HTTP client with defaults (axios instance).

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

Client is a type exported by gox. Methods on this type are documented separately.

Signature

go
type Client struct {
	HTTP           *http.Client
	BaseURL        string
	DefaultHeaders http.Header
	RetryOn5xx     bool
}

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"

c := client.New()
resp, err := c.Get(ctx, "https://api.example.com/users", nil)

Example

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

c := client.New()
resp, err := c.Get(ctx, "https://api.example.com/users", nil)

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