Hi all, Wondering if we can call API synchronously...
# ktor
a
Hi all, Wondering if we can call API synchronously using Ktor Engine. Actually, whenever I'm getting 401 Authorization Token Expired error, I've to call Login API implicitly from Authenticator. Now this api call need to be called synchronously as after getting login API response, i've to update the header with Auth Token and return the request again from authenticate method. Thanks
i
You don't have to call the APIs in a blocking way. Ktor interceptor can take suspend functions, see how AuthProvider does it. https://github.com/ktorio/ktor/blob/b5b59ca3ae61601e6175f334e6a1252609638e61/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt#L39 You also might want to block all other requests until the login is complete (and not send duplicate login requests), see https://github.com/ktorio/ktor/commit/9ea85698bca94113a71c65677ef6a1e1de379a07.
a
Thanks , let me check