In theory, we looked at how to make a POST request to the Fake API to create a todo (https://jsonplaceholder.typicode.com/todos):
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
suspend fun main(args: Array<String>) {
val client = HttpClient(CIO)
val response: HttpResponse = client.post("https://jsonplaceholder.typicode.com/todos") {
headers {
append(HttpHeaders.ContentType, "application/json")
}
setBody("""{"userId": 1, "title": "My new todo!"}""")
}
println(response.status)
println(response.headers)
println(response.bodyAsText())
client.close()
}
Modify the code from the theory so that the following JSON object is sent to the server:
{
"userId": 1,
"title": "My awesome todo!",
"completed": true
}
Run this code yourself and see what response the server returns. Copy the response body and paste it into the response field.