Can we dynamically add data source headers

edited December 18, 2017 in Questions
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  
Request 2 HeaderA : tokenY Response 2 HeaderB : tokenY
Request 3 HeaderB : tokenY Response 3 HeaderA : tokenX
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?

Comments

  • edited December 14, 2017
    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.


  • edited December 14, 2017
    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?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!