Having trouble retrieving information from the local API in React-Native

Currently, I have a web application built using React and an API developed in Laravel. Now, I am planning to create a mobile app that will also utilize the same API. However, I'm encountering an issue where I cannot fetch data due to receiving the error message:

NETWORK REQUEST FAILED.

This is the code snippet I am using to attempt fetching the data:

handleButton = () => {
    try {
        fetch(`127.0.0.1:8081/test`).then(response =>
        console.log(response)
    );
        } catch (e) {
            console.log(e);
        }
    };

I have attempted solutions like changing the IP address in the dev settings to my machine id or using localhost instead of the IP address 127.0.0.1, but unfortunately, these attempts did not resolve the issue. The error message I keep encountering states:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:42556:18)
    at XMLHttpRequest.dispatchEvent (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:47998:27)
    at XMLHttpRequest.setReadyState (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46859:20)
    at XMLHttpRequest.__didCompleteResponse (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46686:16)
    at blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46796:47
    at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16875:37)
    at MessageQueue.__callFunction (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16488:44)
    at blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16245:17
    at MessageQueue.__guard (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16442:13)
    at MessageQueue.callFunctionReturnFlushedQueue (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16244:14)

EDIT:

To interact with my Android Studio emulator, as I do not currently own an Android device running on Android version above 5.

Answer №1

Find the IP address of your device on the local network.

Access the command line interface.

For Mac users, utilize the ifconfig command, typically found under en0. Look for an output like 192.168.0.32 or similar.

For Windows users, use the ipconfig command.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The $OnChange function fails to activate when passing an object by reference

Hi there, I've encountered a problem in my code that I'd like some help with. In my example, I have two components: Parent Component and Child Component. Both components share a field called rules. The Parent Component passes the rules field to ...

Is there a way for me to access the information within these curly brackets [[]}?

I'm facing a challenge where I need to extract the ID from an API response that is formatted in a way unfamiliar to me. As a result, I'm unsure of how to retrieve the ID data from this response. (This is my initial query, so if it's unclear ...

Hover over the sprites using the "spritely" plugin to see the magic unfold

I'm looking to initiate an animation when the mouse hovers over a sprite and have it stop when the mouse moves away. After exploring various solutions, I found one that seemed promising: Why does jQuery spritely animation play an extra frame on secon ...

Angular route unable to detect Passport User Session

The navigation bar in the header features buttons for Register, Login, and Become a Seller. Upon user login, it displays logout and view profile buttons. This functionality is operational on all routes except one, causing a client-side error. user not def ...

Merge web address when form is sent

I'm currently working on a search application using the Django framework and the Yelp API as my backend, which is functioning properly. However, I am facing some challenges with the frontend development, specifically integrating Leaflet.js. My search ...

Attempting to include a new choice on a drop-down menu and ensure its visibility within the drop-down menu

On my journey into the world of web development, I am facing a challenge with adding an option to a dropdown list. Despite pressing the add button to insert "Pasta" as a new option, it is not showing up in the list immediately. However, selecting all optio ...

Updating text color with Ajax response value

I need assistance with updating the text color of a sensor value displayed using html/ajax. Currently, the sensor value is being displayed successfully, but I want the text color to change based on the value. Here's an example: if value < 50 then f ...

Is there a straightforward method to retrieve all information from Vue.js?

Is there a way to extract all of this data? I've attempted using this._data.forEach but it doesn't seem to be effective. Thank you! data() { return { childData: '', credit: '', company: '', email: ...

Error: Attempting to access a property of an undefined value (referencing '8') was unsuccessful

Hello everyone, I am new to posting and identify as a junior Frontend developer. I'm encountering a confusing issue with the InputLabel from Material UI (ver. 5) on a specific section of the website I'm working on. On the homepage, I successfully ...

Is it possible to modify the CSS styling in React using the following demonstration?

I am attempting to create an interactive feature where a ball moves to the location where the mouse is clicked. Although the X and Y coordinates are being logged successfully, the ball itself is not moving. Can anyone help me identify what I might be overl ...

Is it possible to display a combination of images and text data using JQUERY/AJAX, when the data is sent as objects or arrays?

I'm struggling to figure out how to handle an object or array sent from a server that contains binary picture and text data using JQUERY/AJAX Here is the server-side setup: const url= require('url'), express = require('express&ap ...

Enhance user interactivity by incorporating dynamic checkboxes, radio buttons, checkbox groups, and radio button groups using Ext

Hello to all the amazing folks at Stack Overflow! I've tried searching for a solution to this issue on Stack Overflow, but I couldn't find anything helpful. Here is my model: Ext.define('soru', { extend: 'Ext.data.Model' ...

Troubleshooting Socket.IO Communication: Client's emits not reaching server

I have implemented a real-time notification service in a web app using Express and Socket.IO. The client can successfully connect to the server and receive emits from it. However, I am facing an issue where the server is not receiving emits from the client ...

Navigating JSON data to retrieve a specific property in AngularJS using a select form

Struggling with AngularJS and JSON. I have a form.html view where users can select their province. I have a Province JSON file for the select tag, but when storing in MySQL, I need the province Id. I tried using ng-value="province.id" in the option tag but ...

My AJAX request seems to be redirecting to my PHP file instead of simply returning the response text. What could be causing this issue?

I am currently working on a project for my Web Engineering course and I am incorporating jQuery to execute an AJAX request to my PHP file using the POST method. The task specifies that "each time the [submit] button is pressed, the form data should be disp ...

Develop an outline using D3.js for the clipath shape

After successfully creating a shape with a color gradient, I encountered the need for further customization. If you are interested in this topic, check out these related questions: Add multi color gradient for different points in d3.js d3.js scatter plot c ...

Having difficulty rearranging choices within an optgroup

This is a dropdown <select id="officer-id" placeholder="Choose an officer"> <option selected="selected" >----</option> <optgroup id="pt1" label="To be reviewed"> <option value=&ap ...

Incorporate React JS seamlessly into your current webpage

As I delve into learning React and considering migrating existing applications to React, my goal is to incorporate a React component within an established page that already contains its own HTML and JavaScript - similar to how KnockoutJS's `applyBindi ...

JavaScript TypeError - missing method issue

When I try to call this code, I am encountering a TypeError: player = new Player({name:''}); Player = MeteorModel.extend({ schema:{ name:{type:String,}, value:{} }, belongsTo:{ meteorCollection:'', methodName ...

The react-xml-parser package is asking for Babel version "^7.0.0-0", however it was instead loaded with version "6.26.3". I have already attempted all available solutions to resolve this issue

I have attempted numerous solutions from the Github community regarding this issue, but unfortunately none have worked for me. /node_modules/react-xml-parser/dist/bundle.js: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you ha ...