Junior
Jak dodać wartość w metodzie POST w Retrofit?
sobes.tech AI
Odpowiedź od AI
Użyj adnotacji @Field, aby wysłać dane w formacie klucz-wartość (form-encoded) lub @Body z obiektem do wysłania JSON.
Przykład z @Field:
interface ApiService {
@FormUrlEncoded
@POST("users")
suspend fun createUser(
@Field("name") name: String,
@Field("email") email: String
): ResponseBody
}
Przykład z @Body i obiektem danych:
data class User(
val name: String,
val email: String
)
interface ApiService {
@POST("users")
suspend fun createUser(@Body user: User): ResponseBody
}