Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlexPalaz opened this issue May 27, 2024 · 4 comments
Open

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

AlexPalaz opened this issue May 27, 2024 · 4 comments
Labels
needs more information status:needs-more-information An issue that requires additional information from issue author type:question An issue that's a question

Comments

@AlexPalaz
Copy link

AlexPalaz commented May 27, 2024

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

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota May 27, 2024
@koros
Copy link
Contributor

koros commented May 29, 2024

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 koros moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota May 29, 2024
@AlexPalaz
Copy link
Author

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

@koros
Copy link
Contributor

koros commented May 31, 2024

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

@baywet baywet moved this from Waits for author 🔁 to Todo 📃 in Kiota Jun 11, 2024
@baywet baywet added question needs more information status:needs-more-information An issue that requires additional information from issue author type:question An issue that's a question labels Jun 11, 2024
@fey101 fey101 removed the question label Jul 4, 2024
@BrianUribe6
Copy link

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

public static getDefaultMiddlewares(customFetch: (request: string, init: RequestInit) => Promise<Response> = (...args) => fetch(...args) as any): Middleware[] {

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more information status:needs-more-information An issue that requires additional information from issue author type:question An issue that's a question
Projects
Status: New📃
Development

No branches or pull requests

5 participants