Have created a simple GET API using node.js and trying to consume it within my expo-react native project using axios/fetch.
The GET API is called whenever user clicks on submit button.
Submit -> http://localhost:port/api
However, when I am trying to test the feature on my android device by connecting the device through datacable and selecting “local” connect type in expo, the API call always falls under exception.
When I tried to log the exception, the exception is printed empty.
I double checked the API and it works fine when tested through postman.
I tried replacing localhost url with my-Ip (http://IP:port/api) and also with 127.0.0.1/127.0.2.2 (http://127.0.0.1:port/api , http://127.0.2.2:port/api) , but nothing seems to make the API call a success.
When I replaced the localhost URL with Facebook’s network sample API, the application worked just fine. So, there is no issue with the API calling method.
Also, tried adding the port to windows inbound firewall request but that didn’t work too.
Can someone help me out with this ?
3
Answers
yes, i also had this problem until use my Local IP (example: http://192.168.1.55:port) instead 127.0.0.1
please see this answer
You must call the API from your local IP address. To get your local IP, just do the following:
If you are on Ubuntu 16.04:
If you are on Ubuntu 18.04:
Your local IP address will probably be something like
192.168.0.XXX
.Good day,
This is working
I use my machine’s IP the Ethernet adapter Ethernet 2: IPV4 Address
And allow my port on firewall both Inbound and outbound rules