Need implementation pattern for REST token header fetch and set
-
Hello,
From within my Qt client I need to make REST calls. The first call is to authenticate and get a token from the server. After that, for all subsequent calls, the token will be set in the header as a bearer token.Since all the calls via QNetworkAccessManager are asynchronous, I need to chain the calls. First do the authentication. If and when that is successful, then execute the next call.
This is more a Qt asynchronous coding question. How can I chain multiple asynchronous calls? Executed the first QNetworkAccessManager call, after successfully processing the slot for the first call, then I need to make the second QNetworkAccessManager call, process the slot for the second call.
Can you please give me guidance on how to implement this.
Thanks.
-
Hello,
From within my Qt client I need to make REST calls. The first call is to authenticate and get a token from the server. After that, for all subsequent calls, the token will be set in the header as a bearer token.Since all the calls via QNetworkAccessManager are asynchronous, I need to chain the calls. First do the authentication. If and when that is successful, then execute the next call.
This is more a Qt asynchronous coding question. How can I chain multiple asynchronous calls? Executed the first QNetworkAccessManager call, after successfully processing the slot for the first call, then I need to make the second QNetworkAccessManager call, process the slot for the second call.
Can you please give me guidance on how to implement this.
Thanks.
@JohnGa
You just need to await (i.e. do nothing, let the Qt event loop run, until signal arrives) either finished or error on the network reply to your first request, then you are ready to send the second one.You can maintain state for where you are --- e.g. a list of calls to make or functions to call after each one or state/number --- in a single slot handler if you wish. Rather than, say, keep changing which slot function is connected for each call.