In React Native, a GET API request is used to fetch data from a server. The most common way is by using the built-in fetch() function to retrieve JSON data from REST APIs.
fetch() returns a PromiseuseEffect and useState are commonly usedThe basic syntax for a GET request in React Native:
fetch(url).then(response => response.json())
// Simple GET API example using fetch
import React, { useEffect, useState } from "react";
import { View, Text, FlatList } from "react-native";
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
// 1. Fetch data from API
fetch("https://jsonplaceholder.typicode.com/posts?_limit=5")
.then(response => response.json())
.then(json => setData(json))
.catch(error => console.error(error));
}, []);
return (
<View>
<Text>Total Records: {data.length}</Text>
{/* 2. Display Data */}
<FlatList
data={data}
keyExtractor={({ id }) => id.toString()}
renderItem={({ item }) => (
<Text>{item.title}</Text>
)}
/>
</View>
);
};
export default App;
The app sends a GET request to the API URL. The server responds with JSON data, which is stored in state and displayed in the UI.
This simulator mimics a mobile screen. Click the button below to execute a real fetch() request to a public API and render the results, just like React Native.
Status: Idle
.catch()async/await for cleaner codeFlatList