Request Hooks
chriddyp opened this issue · 4 comments
The API requests that Dash's front-end makes should be configurable. In order to make them configurable, we will need to do the following things:
- We will need to make the Dash Front-end (
dash-renderer
) a standalone library that can be initialized and invoked from other libraries - We will need to extend the
dash-renderer
to take a set of config input parameters - Some of these input parameters will be functions or promises that we will call before certain actions
- For this issue, we will start by a
request_pre
andrequest_post
parameter that will be called before and after HTTP requests with the entire request and response objects. This will enable the developer to transform the data before and after network requests.
Example:
dash_renderer({
request_pre: requestPayload => {
return modifyRequest(requestPayload);
},
request_post: (requestPayload, responsePayload) => {
return modifyResponse(requestPayload, responsePayload)
}
})
So, the hooks are only the network requests. In the code, this would fit in here:
dash-renderer/src/actions/index.js
Lines 447 to 455 in 70bb93e
Note that in order for users to supply their own arguments, I believe they would need to provide their own instance of dash_renderer
by overriding the index file (as discussed here: plotly/dash#265)
Hi,
What does the Sponsored label means, and are there any plans to release this feature soon?
This was released in #75
It seems that certain types of responses do not trigger request_post
. Namely:
- On initial load (i.e. not in response to user interaction) only
request_pre
is fired but notrequest_post
. - There is no hook for failed responses.
I am currently using fetch-intercept to provide custom loading indicators and I was hoping I could switch to custom Dash hooks but it's not possible due to issues describved above. fetch-intercept
, on the other hand,, works perfectly as it provides me with responseError
hook and it always fires (including on initial load).
Separately, it'd be nice if the hooks provided access to the actual Fetch request / response objects to inspect or modify.. I'll have to stick with fetch-intercept
for now.
Please make an issue for the problems you've encountered at https://github.com/plotly/dash/issues
This repo is obsolete, the renderer has been merged into the main dash repo.