A GET request asks a server to send data to the app. It is like asking for information without changing anything on the server.
Click to reveal answer
beginner
What is a POST request used for?
A POST request sends data from the app to the server. It is used to create or update information on the server.
Click to reveal answer
intermediate
Which Kotlin library is commonly used for making GET and POST requests in Android?
OkHttp is a popular Kotlin library for making HTTP requests like GET and POST in Android apps.
Click to reveal answer
beginner
In a POST request, where do you put the data you want to send?
You put the data in the request body, usually as JSON or form data.
Click to reveal answer
beginner
Why should network requests be done off the main thread in Android?
Because network calls can take time, doing them on the main thread would freeze the app UI. Using background threads keeps the app responsive.
Click to reveal answer
Which HTTP method is used to retrieve data without changing the server?
APUT
BPOST
CGET
DDELETE
✗ Incorrect
GET requests ask the server to send data without modifying it.
Where is data sent in a POST request?
AIn the request body
BIn the request headers
CIn the response
DIn the URL
✗ Incorrect
POST requests send data inside the request body.
Which Kotlin library is commonly used for HTTP requests in Android?
ARetrofit
BOkHttp
CGlide
DRoom
✗ Incorrect
OkHttp is a popular library for HTTP networking in Kotlin Android apps.
Why should network requests not run on the main thread?
AThey use too much memory
BThey do not work on the main thread
CThey are faster on the main thread
DThey can freeze the UI
✗ Incorrect
Network calls can take time and freeze the UI if run on the main thread.
What does a POST request usually do?
ASends data to create or update on the server
BRetrieves data from the server
CDeletes data on the server
DUpdates the app UI
✗ Incorrect
POST requests send data to the server to create or update resources.
Explain the difference between GET and POST requests in Android apps.
Think about asking for information versus sending information.
You got /4 concepts.
Describe why network requests should be done on background threads in Android.
Imagine waiting for a slow response while trying to use the app.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a GET request in Android Kotlin networking?
easy
A. To fetch data from a server
B. To send data to a server
C. To update the UI thread
D. To store data locally
Solution
Step 1: Understand GET request purpose
A GET request is used to retrieve or fetch data from a server without changing any data on the server.
Step 2: Compare with other request types
POST requests send data to the server, unlike GET which only fetches data.
Final Answer:
To fetch data from a server -> Option A
Quick Check:
GET = fetch data [OK]
Hint: GET fetches data; POST sends data [OK]
Common Mistakes:
Confusing GET with POST request purpose
Thinking GET modifies server data
Mixing UI updates with network requests
2. Which of the following is the correct way to start a POST request using Kotlin's HttpURLConnection?
easy
A. connection.requestMethod = "GET"
B. connection.requestMethod = "POST"
C. connection.method = "POST"
D. connection.setRequestMethod("GET")
Solution
Step 1: Identify correct property for request method
In Kotlin, HttpURLConnection uses requestMethod property to set the HTTP method.
Step 2: Confirm correct method value for POST
To make a POST request, set requestMethod to "POST" exactly.
Final Answer:
connection.requestMethod = "POST" -> Option B
Quick Check:
POST method set by requestMethod = "POST" [OK]
Hint: Use requestMethod property with "POST" string [OK]
Common Mistakes:
Using wrong property name like method
Setting GET instead of POST
Using Java-style setRequestMethod() in Kotlin
3. What will be the output of this Kotlin code snippet when making a GET request?
val url = URL("https://example.com/data")
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"
val responseCode = connection.responseCode
println(responseCode)
medium
A. 500
B. 404
C. 200
D. Compilation error
Solution
Step 1: Understand the code flow
The code opens a connection to the URL and sets the method to GET, then reads the response code from the server.
Step 2: Predict typical HTTP response code
Assuming the URL is valid and reachable, a successful GET request returns HTTP status code 200.
Final Answer:
200 -> Option C
Quick Check:
Successful GET returns 200 [OK]
Hint: 200 means OK response from server [OK]
Common Mistakes:
Assuming responseCode is a string
Confusing 404 (not found) with success
Thinking code will not compile
4. Identify the error in this Kotlin code snippet for sending a POST request:
val url = URL("https://example.com/api")
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "POST"
val outputStream = connection.outputStream
outputStream.write("data=hello".toByteArray())
outputStream.flush()
outputStream.close()
medium
A. Missing setting connection.doOutput = true
B. Using write() instead of writeBytes()
C. Incorrect requestMethod value
D. Not reading the response code
Solution
Step 1: Check POST request setup
For POST requests, doOutput must be set to true to send data in the request body.
Step 2: Identify missing property
The code does not set connection.doOutput = true, so writing to outputStream will fail or not send data.
Final Answer:
Missing setting connection.doOutput = true -> Option A
Quick Check:
doOutput = true needed for POST body [OK]
Hint: Set doOutput true before writing POST data [OK]
Common Mistakes:
Forgetting doOutput = true for POST
Confusing write() method usage
Ignoring response reading after POST
5. You want to send JSON data in a POST request using Kotlin. Which sequence correctly sets up the connection and sends the JSON string {"name":"John"}?
hard
A. Set requestMethod to "GET", write JSON bytes to outputStream, set doOutput = true
B. Set requestMethod to "POST", set doOutput = false, write JSON string directly to connection
C. Set requestMethod to "POST", write JSON bytes to outputStream without setting doOutput, set Content-Type header to "text/plain"
D. Set requestMethod to "POST", set doOutput = true, set Content-Type header to "application/json", write JSON bytes to outputStream
Solution
Step 1: Correct HTTP method and output setup
For sending data, requestMethod must be "POST" and doOutput must be true to allow writing data.
Step 2: Set proper headers and write data
Content-Type header should be "application/json" to indicate JSON data. Then write JSON bytes to outputStream.
Final Answer:
Set requestMethod to "POST", set doOutput = true, set Content-Type header to "application/json", write JSON bytes to outputStream -> Option D
Quick Check:
POST + doOutput + JSON header + write bytes [OK]
Hint: POST JSON needs doOutput true and JSON content-type [OK]
Common Mistakes:
Using GET method to send data
Not setting Content-Type header correctly
Forgetting doOutput = true
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.