Main Activity
val retrofit = Retrofit.Builder()
.baseUrl("http://192.168.1.78:3000")
.addConverterFactory(GsonConverterFactory.create())
.build()
val api = retrofit.create(ApiService::class.java)
api.fetchLastNews().enqueue(object : Callback<List<News>>{
override fun onResponse(call: Call<List<News>>, response: Response<List<News>>) {
d("exemplo","onResponse")
}
override fun onFailure(call: Call<List<News>>, t: Throwable) {
d("exemplo","onFailure")
}
})
}
Interface
interface ApiService {
@GET("/getultimas")
fun fetchLastNews(): Call<List<News>>
}
Data class
package com.example.navigationdrawer
data class News (
val titulo: String
)
Response from node api
app.get('/getultimas', function (req, res) {
console.log("ultimas noticias");
results = transform(jsonLastNews);
res.json(results);
});
Its giving error retrofit kotlin expected begin_object but was begin_array