Sheroz Nazhmudinov
get
MissingFieldException
post
@Serializable data class RegistrationParams( val name: String, val job: String ) @Serializable data class RegistrationResponse( @SerialName("name") val name: String, @SerialName("job") val job: String, @SerialName("id") val id: String, @SerialName("createdAt") val createdAt: String ) val httpClient = HttpClient(Android) { install(JsonFeature) { val json = Json { ignoreUnknownKeys = true } serializer = KotlinxSerializer(json = json) } } suspend fun samplePostRequest(): RegistrationResponse = <http://client.post|client.post>( urlString = "<https://reqres.in/api/users>", ) { body = Json.encodeToString( RegistrationParams.serializer(), RegistrationParams( name = "Neo", job = "The Chosen One" ) ) }
Field 'name' is required, but it was missing
Joost Klitsie
body = RegistrationParams(name = "Neo", job = "The Chosen One")
contentType(ContentType.Application.Json)
A modern programming language that makes developers happier.