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

Response

Overview ​

Response wraps an HTTP response.

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

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

Signature ​

go
type Response struct {
	*http.Response
}

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"

if resp.StatusCode() != 200 {
    return fmt.Errorf("unexpected status %d", resp.StatusCode())
}
var body User
if err := resp.JSON(&body); err != nil {
    return err
}

Example ​

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

if resp.StatusCode() != 200 {
    return fmt.Errorf("unexpected status %d", resp.StatusCode())
}
var body User
if err := resp.JSON(&body); err != nil {
    return err
}

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