Can we dynamically add data source headers

I’m working with a legacy proprietary REST API. The initial authentication token is returned in the body of one API call and I can retrieve it with no problem. For subsequent calls, an authentication token must be passed in a header variable.

Just to make things more interesting, on each call, the system may return a new token and/or a new header variable. For example:

Request 1 HeaderA : tokenZ Response 1 HeaderA : tokenY <br> Request 2 HeaderA : tokenY Response 2 HeaderB : tokenY <br> Request 3 HeaderB : tokenY Response 3 HeaderA : tokenX <br> Request 4 HeaderA : tokenX etc...

The header variable can be one of two possibilities, so identifying it is not difficult. However, I need some way to save the header variable and value from the response and set it on the next request. As far as I can tell there is no way to retrieve header variables in the model nor can I see a way to add a header variable to the data source before the request is made.

Anyone have any suggestions?

The short answer is: we don’t have any way to do this declaratively.

When REST Models are loaded, we don’t store the returned headers anywhere, so this is not currently doable using REST Models. We could add that in the future, but nothing there right now.

So, right now, if you’re desperate to do this, you’re left with some pretty involved workarounds involving JavaScript. We can go into more depth on this if needed.


So it seems the next option would be to define UI-only models, build and send the request using XHR, and manually populate the models with the result.

Is there a documented API or accepted technique for doing this? Something that will be supported in future releases?