Recall & Review
beginner
What is a POST request in mobile app development?
A POST request sends data from the app to a server, often to create or update information. It's like sending a letter with details to someone who will process it.
Click to reveal answer
beginner
How do you add a JSON body to a POST request in Swift?
You create a dictionary with your data, convert it to JSON using JSONSerialization, then set it as the HTTP body of the URLRequest.
Click to reveal answer
beginner
Why do you need to set the 'Content-Type' header to 'application/json' in a POST request?
It tells the server that the data sent is in JSON format, so the server knows how to read it correctly.
Click to reveal answer
beginner
What Swift class is used to make HTTP requests?URLSession is used to create tasks that send and receive data over the network.
Click to reveal answer
beginner
What is the role of URLRequest in making a POST request?
URLRequest holds the URL, HTTP method, headers, and body data for the request before sending it with URLSession.
Click to reveal answer
Which HTTP method is used to send data to a server to create or update resources?
✗ Incorrect
POST is used to send data to the server, often to create or update resources.
In Swift, which class is responsible for sending network requests?
✗ Incorrect
URLSession manages network tasks like sending requests and receiving responses.
What must you set in the HTTP headers to indicate the body contains JSON data?
✗ Incorrect
Setting 'Content-Type' to 'application/json' tells the server the body is JSON.
How do you convert a Swift dictionary to JSON data for the request body?
✗ Incorrect
JSONSerialization converts dictionaries to JSON Data for the HTTP body.
Which property of URLRequest sets the HTTP method like POST or GET?
✗ Incorrect
The httpMethod property defines the HTTP method for the request.
Explain step-by-step how to create and send a POST request with a JSON body in Swift.
Think about preparing the request, adding data, and sending it.
You got /7 concepts.
Why is it important to handle errors when sending a POST request in a mobile app?
Consider what can go wrong when talking to a server.
You got /5 concepts.