Search code examples
asp.netwindowsreact-nativeasp.net-coreexpo

How to connect React Native Expo App to a backend ASP .NET Core API running locally?


I am making this hobby project where I want to make an App for pinging others in a group about some kind of event happening (it's for League of Legends gaming purpose lol).

I try to connect my Expo App to my locally running .Net Core API. I am running it on Windows and the same Wi-Fi. I've tried both https and http request from my phone to my app but neither work. The request doesn't even seem to get into the server, though I am not sure how to check if that's true.

I guess I need some help with setting up the server so that I can make requests into it. I paste my request code below.

async function getAllUsers() {
console.error("Fetching data");

const response = await fetch(
"http://localhost:5225/LoLCaller/get-all-users",
{
  method: "GET",
  headers: {
    "Content-Type": "application/json",
  },
});

 const data = await response.json();
 console.log(data);
 return data;
}

in the code I change the localhost to my local pc's IP that I don't want to share here :D

Thanks a lot for any help!


Solution

  • You can use ngrok to forward your server's local address to some other address.

    Use: ngrok http 5225

    it'll give you a URL, which you can use it as your server's address.