Please allow for a callback in the $.request "header" function
https://github.com/dsherret/dax/tree/6aed9b02ccf4debeeb0581f7f576468721631260?tab=readme-ov-file#making-requests
Would you consider accepting a callback for the header in the $.request API? If you promises? The example below would be ideal. The callback would allow me to return the request object for more manipulations without having to make the entire method async. It really only needs to be async when the call chain gets to some method that will make the request, like .json() or .text() which is when callbacks, like the one below, can get resolved.
export function myApiRequest(path: string) {
return $.request(baseUrl + path).
header("Authorization", async ()=> "Bearer " + await getAccessToken()). // please support [async] callback
header('Content-Type', 'application/json')
}
It is not just convenience, the access token may have expired by the time the caller actually gets around to making the request. With the callback, getAccessToken can re-new the token without interrupting the work-flow.
Alternatively, this should cover more ground and require less API changes in dax:
export function myApiRequest(path: string) {
return $.request(baseUrl + path).
header('Content-Type', 'application/json').
beforeRequest(async builder=> {
return builder.header("Authorization", "Bearer " + await getAccessToken())
})// returns RequestBuilder
}