kiota-typescript icon indicating copy to clipboard operation
kiota-typescript copied to clipboard

[React Native iOS] Kiota is not working with React Native iOS

Open AlexPalaz opened this issue 1 year ago • 4 comments

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 custom apiClientProxifier removing all the throw new Error and it works until send method inside the FetchRequestAdapter. So I'm supposing there's an issue inside the apiClientProxifier and specially on FetchRequestAdapter.

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

AlexPalaz avatar May 27 '24 13:05 AlexPalaz

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

koros avatar May 29 '24 15:05 koros

Hi @koros, I'm testing on real device but I've also tried with emulator but didn't work unfortunately

AlexPalaz avatar May 29 '24 16:05 AlexPalaz

@AlexPalaz Alright thanks for the info I'll set up a similar environment.

koros avatar May 31 '24 09:05 koros

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.)

https://github.com/microsoft/kiota-typescript/blob/8e980dacbd77b72598db65df1b8379fc70feb655/packages/http/fetch/src/middlewares/middlewareFactory.ts#L27

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);
}


BrianUribe6 avatar Sep 19 '24 20:09 BrianUribe6

Thank you for the additional information.

Since we've not received feedback/upvotes on this issue in a while, I'm going to go ahead and close it for now. Feel free to comment/provide additional context if this is still relevant.

baywet avatar Jan 20 '25 19:01 baywet