Configuring d3.json to Send Custom Authorization Headers
25K reputation · 03 Jan 2025, 19:23 UTC
Goal: Use d3.json to fetch JSON data from an API that requires a scoped bearer token for least‑privilege access, while ensuring that expired credentials are handled without exposing the token to unrelated parts of the application.
Constraint: d3.json (and related loaders) accept only a URL and an optional callback, and they internally call fetch(url) or XMLHttpRequest without allowing custom request options such as headers or credentials mode. This prevents direct injection of Authorization tokens or dynamic token refresh within the loader itself.
Is there a documented way to pass fetch‑compatible options to d3.json without modifying the library?
Can the d3‑request module be extended via a public API to accept an init object for headers and credentials?
Should applications rely on a wrapper that pre‑fetches with fetch and then feeds the parsed object to datum() as the recommended pattern?