Documentation
¶
Overview ¶
Package response provides the Response type for SDK results.
Index ¶
- Constants
- func FetchFormatted[R any](ctx context.Context, httpClient *internalhttp.Client, path string, ...) (R, error)
- func FetchFormattedChunked[R any](ctx context.Context, httpClient *internalhttp.Client, path string, ...) (R, error)
- func FetchFormattedMap[K comparable, R any](ctx context.Context, httpClient *internalhttp.Client, keys []K, ...) (map[K]R, error)
- func IsNoData(statusCode int) bool
- type CSVResponse
- type HTMLResponse
- type RateLimitMeta
- type Response
Constants ¶
const ( NoDataBody = "0\r\n\"\"\r\n" NoDataBodyNoHeaders = "\"\"\r\n" )
NoDataBody and NoDataBodyNoHeaders are the exact bodies production returns for a formatted (CSV) request that finds no data — with headers on (the default) and with headers=false — captured 2026-08-19 against /v1/stocks/candles/D/RIVN/ for 2015 and re-verified 2026-08-25. The CRLF line endings are the API's own. They are the single source for the shape noDataChunk recognizes: the unit fixtures consume them verbatim, and integration's TestWireShape_FormattedNoData re-fetches them live — so if the API changes the shape, a test fails instead of the fail-open filter silently ceasing to match.
Variables ¶
This section is empty.
Functions ¶
func FetchFormatted ¶
func FetchFormatted[R any](ctx context.Context, httpClient *internalhttp.Client, path string, params url.Values, format string, wrap func(*internalhttp.Response) R) (R, error)
FetchFormatted issues a GET requesting a non-JSON wire format (format=csv or format=html, see ADR-018) and wraps the raw response with wrap (NewCSV or NewHTML). Shared by every service's CSV (exported) and HTML (unexported) facets so the fetch-and-wrap boilerplate exists exactly once.
func FetchFormattedChunked ¶
func FetchFormattedChunked[R any](ctx context.Context, httpClient *internalhttp.Client, path string, chunkParams []url.Values, format string, wrap func(*internalhttp.Response) R) (R, error)
FetchFormattedChunked issues one request per element of chunkParams concurrently against the same path, cancelling the remaining requests on the first error (ADR-014, mirrored from the JSON candle-splitting path), then merges the raw bodies in order and wraps the merged text with the response metadata of the last chunk that carried data — the same contract the JSON path documents. A single chunk skips the concurrency machinery entirely and behaves exactly like FetchFormatted.
Chunks the API answered with no data are dropped before the merge, the way the JSON path filters NoData chunks. Without that they corrupt the output twice over: their placeholder lines land in the merged text, and because mergeTextChunks takes its reference header from the first body, an empty oldest chunk (the likeliest one, since it predates the listing) makes every later chunk keep its own header row inline. See noDataChunk for why the detection has to be structural.
func FetchFormattedMap ¶
func FetchFormattedMap[K comparable, R any](ctx context.Context, httpClient *internalhttp.Client, keys []K, requestFor func(K) (path string, params url.Values, err error), format string, wrap func(*internalhttp.Response) R) (map[K]R, error)
FetchFormattedMap issues one request per key concurrently against a per-key path/params (built by requestFor, which may reject a key whose options do not validate), cancelling the rest on the first error (ADR-014) — used by facets whose JSON counterpart fans out per-symbol into a slice instead of merging into one result (e.g. options.Quotes). Unlike the JSON path, there is no NoData omission: every key gets an entry in the returned map holding whatever the API sent for it, since these facets have no NoData concept (see ADR-018).
Types ¶
type CSVResponse ¶
type CSVResponse struct {
Response
}
CSVResponse carries a raw CSV response body (requested with format=csv; see ADR-018) alongside the same per-request metadata as Response. Unlike Response, it has no NoData field: the API's own no-data signal is not consistent between JSON and CSV (verified live — see ADR-018), so the raw body is handed to the caller exactly as the API sent it, whatever it is.
func NewCSV ¶
func NewCSV(httpResp *internalhttp.Response) *CSVResponse
NewCSV creates a CSVResponse from an internal HTTP response requested with format=csv.
func (*CSVResponse) CSV ¶
func (r *CSVResponse) CSV() string
CSV returns the raw CSV response text, exactly as the API sent it.
type HTMLResponse ¶
type HTMLResponse struct {
Response
}
HTMLResponse carries a raw HTML response body (requested with format=html; see ADR-018) alongside the same per-request metadata as Response. The facet that reaches this type is deliberately unexported today — the API does not serve HTML for any data endpoint yet (verified live: format=html 404s). The type exists so enabling it later is a small, low-risk change instead of new design.
func NewHTML ¶
func NewHTML(httpResp *internalhttp.Response) *HTMLResponse
NewHTML creates an HTMLResponse from an internal HTTP response requested with format=html.
func (*HTMLResponse) HTML ¶
func (r *HTMLResponse) HTML() string
HTML returns the raw HTML response text, exactly as the API sent it.
type RateLimitMeta ¶
RateLimitMeta contains per-response rate limit information.
type Response ¶
type Response struct {
*http.Response
// NoData is true when a 404 indicated no data was available (not an error).
NoData bool
// RateLimit contains per-request rate limit metadata (request-scoped).
RateLimit RateLimitMeta
// contains filtered or unexported fields
}
Response carries per-request metadata returned alongside typed data. It embeds *http.Response, giving callers access to raw headers, status, etc.
Most callers can ignore it with a blank identifier:
quote, _, err := client.Stocks.Quote(ctx, "AAPL")
func New ¶
func New(httpResp *internalhttp.Response) *Response
New creates a Response from an internal HTTP response.
func NewNoData ¶
func NewNoData(httpResp *internalhttp.Response) *Response
NewNoData creates a Response indicating no data was available (404 or 204).
func (*Response) Body ¶
Body returns the raw response body exactly as the API sent it, for logging, debugging, or decoding a payload the typed models do not cover. The SDK reads http.Response.Body to completion when the request is made, so the embedded field is already drained; this is the only way to reach the bytes.
The returned slice is a copy: mutating it cannot corrupt a later Response.SaveToFile or a second call. It is nil when no body was captured.
func (*Response) SaveToFile ¶
SaveToFile saves the response body to a file.