Recall & Review
beginner
What is the purpose of the Fetch API in React Native?
The Fetch API is used to make network requests, such as getting or sending data to a server, in React Native apps.
Click to reveal answer
beginner
How do you specify a POST request using Fetch API?
You set the method property to 'POST' inside the options object passed to fetch, like: fetch(url, { method: 'POST' }).
Click to reveal answer
beginner
Why do we include headers like 'Content-Type': 'application/json' in a POST request?
Headers tell the server what kind of data is being sent. 'Content-Type': 'application/json' means the data is in JSON format.
Click to reveal answer
beginner
How do you send data in the body of a POST request using Fetch API?
You add a 'body' property with a JSON string, created by JSON.stringify(yourData), inside the fetch options.
Click to reveal answer
beginner
What does the fetch function return and how do you handle the response?
Fetch returns a Promise. You use .then() to handle the response and convert it to JSON with response.json(), then use the data.
Click to reveal answer
Which option correctly sets up a POST request with Fetch API?
✗ Incorrect
To send data with POST, you must set method to 'POST' and include the body as a JSON string.
What header should you add to tell the server you are sending JSON data?
✗ Incorrect
'Content-Type': 'application/json' tells the server the data format is JSON.
What does fetch() return when you call it?
✗ Incorrect
Fetch returns a Promise that resolves to the response object.
How do you convert the fetch response to usable JSON data?
✗ Incorrect
response.json() is a method that returns a Promise resolving to the parsed JSON.
Which is a correct way to handle errors in a fetch POST request?
✗ Incorrect
You handle fetch errors by adding a .catch() block after the .then() chain.
Explain how to make a POST request using Fetch API in React Native.
Think about how you tell the server what you are sending and how you handle the reply.
You got /4 concepts.
Describe the steps to send JSON data to a server and receive a JSON response using Fetch API.
Focus on both sending and receiving JSON data.
You got /4 concepts.