Open AlexPalaz opened 6 months ago
Hi @AlexPalaz, Thank you for using Kiota and raising this issue. Could you please let me know if you are testing on an actual device or an emulator? This information will help me replicate the issue on my end
Hi @koros, I'm testing on real device but I've also tried with emulator but didn't work unfortunately
@AlexPalaz Alright thanks for the info I'll set up a similar environment.
I'm not sure if this is related to the same issue, but when working on React Native (Android) I was unable to send any http requests. The error I was getting were not helpful at all. I got things like TypeError: Network Request Failed
. After further investigation I figured that this might be related to React Native's fetch
API.
When you don't specify a custom fetch callback. Kiota defaults to window.fetch
(or this is what I assume it is getting transpiled to.)
To fix this all you need to do is to create an instance of HttpClient
and pass it your own fetch callback, and then use it to create your client.
function createRequestAdapter(provider: AuthenticationProvider) {
// By Default it will use window.fetch if a fetch function is not specified.
// We need to explicitly instantiate HttpClient and specify React Native's fetch.
const httpClient = new HttpClient(fetch);
const adapter = new FetchRequestAdapter(
provider,
undefined,
undefined,
httpClient
);
return adapter;
}
function createAPIClient() {
const provider = new AnonymousAuthenticationProvider();
const adapter = createRequestAdapter(provider);
return createMyAPIClient(adapter);
}
Kiota TypeScript integration is not working with React Native. I'm not getting any kind of error on logs. After debugging for a while, seems like that
createClient
from kiota has not being initialized. I tried to create a customapiClientProxifier
removing all thethrow new Error
and it works untilsend
method inside theFetchRequestAdapter
. So I'm supposing there's an issue inside theapiClientProxifier
and specially onFetchRequestAdapter
.I tried on React Native Web and Kiota works fine, but on iOS is not working.
Tested on:
OS: iOS 17.5.1 React Native: 0.74.1 Expo SDK 50