Documentation
¶
Overview ¶
Command response-formats demonstrates the *Response value every context-first SDK method returns alongside its typed data — the part most examples discard with a blank identifier.
It covers four things the other examples never touch:
- the CSV facet (client.Stocks.AsCSV() and friends), which asks the API for format=csv and hands back the raw text
- the format predicates (IsJSON / IsCSV / IsHTML)
- Response.Body(), the raw payload as the API sent it
- Response.SaveToFile(), which writes that payload straight to disk
It also shows the correct way to total API credits for a session: sum resp.RateLimit.Consumed across your own calls. client.RateLimits() is a snapshot of the last completed response, so its Consumed field is what that single request cost — not a running total. The other examples' footers say so and point here.
Usage:
go run ./examples/response-formats [-symbol AAPL] [-outdir /tmp/md]
Click to show internal directories.
Click to hide internal directories.