0
0
React Nativemobile~5 mins

Fetch API for POST requests in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Afetch(url, { method: 'POST', body: JSON.stringify(data) })
Bfetch(url, { method: 'GET', body: JSON.stringify(data) })
Cfetch(url, { body: data })
Dfetch(url)
What header should you add to tell the server you are sending JSON data?
A'Accept': 'text/html'
B'Content-Type': 'application/json'
C'Authorization': 'Bearer token'
D'Content-Length': '100'
What does fetch() return when you call it?
AA Promise
BA JSON object
CAn array
DA string
How do you convert the fetch response to usable JSON data?
Aresponse.toJSON()
BJSON.parse(response)
Cresponse.json()
Dresponse.text()
Which is a correct way to handle errors in a fetch POST request?
AUse alert() only
BIgnore errors
CUse try/catch without async
DUse .catch() after .then()
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.