Request options
Set the path, query parameters, per-request headers, and the request and session identifiers on a Request.
Every verb takes a Request (directly, or embedded in GetRequest and the body-carrying requests). Request holds the per-call knobs, so the same client serves many different calls without reconstruction. This guide covers each field.
Path
Path is joined to the client's BaseURL. With a base URL set, pass a leading-slash path.
client.Get(ctx, http.GetRequest{
Request: http.Request{Path: "/users/1"},
})With no BaseURL on the client, pass a full URL as the path.
Query
Query is a url.Values, encoded and appended to the path. Build it with the standard library.
q := url.Values{}
q.Set("page", "2")
q.Add("tag", "edge")
q.Add("tag", "beta")
client.Get(ctx, http.GetRequest{
Request: http.Request{Path: "/users", Query: q},
})
// GET /users?page=2&tag=edge&tag=betaHeaders
Headers is a map[string]string merged onto the client-wide headers for this one call. A per-request header overrides a client header of the same name, so you can set a default on the client and override it per call.
client.Get(ctx, http.GetRequest{
Request: http.Request{
Path: "/users/1",
Headers: map[string]string{
"Authorization": "Bearer " + token,
"Accept": "application/json",
},
},
})The client-wide headers come from Config, covered in Configuring the client.
Request and session identifiers
ID and SessionID are emitted as the X-Request-ID and X-Session-ID headers when set, so a request can be traced across services and correlated within a user session. Set them on the Request rather than in the header map, so they are named where a reader expects them.
client.Post(ctx, http.PostRequest{
Request: http.Request{
Path: "/orders",
ID: "req-123",
SessionID: "sess-abc",
},
Body: payload,
})Both are omitted when empty. The header names are exported as constants, listed in the headers reference.
Stream
Stream is a flag on Request that changes how the response body is returned. Left false, the body is read into resp.Body. Set true, the live body is handed back as resp.Reader for you to read and close, so a large download never round-trips through memory. The dedicated streaming guide covers Server-Sent Events, which use their own methods rather than this flag.