vincent15000's avatar

React native => axios error

Hello,

I'm trying to develop a personal project with React native with Laravel in API mode.

I just try to get some datas from the backend with axios.get(), but I get this error : Axios error - Network error, with no more details.

The backend URL is like this one : http://localhost:8000/api/recipes.

I'm using expo and I access to the application with the QR code directly on my smartphone.

What do you suggest me to check ?

Thanks for your help.

V

0 likes
2 replies
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

I just found the solution.

How foolish of me.

As the application is loaded on the smartphone, I can't use localhost given that it's not on the same computer than the backend.

So I have to specify the host when I run the php server.

php artisan serve --host=192.168.1.14

Then I just have to call the API on this address.

axios.get('http://192.168.1.14:8000/api/recipes');
1 like

Please or to participate in this conversation.