cloudroam
2025-02-21 2167ea58d1c297b0536d5cab6517707f1892b95f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.example.firstapp.database.service
 
import com.example.firstapp.database.entity.ApiResponse
import com.example.firstapp.database.entity.KeywordConfig
import com.example.firstapp.database.entity.KeywordEntity
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
 
/**
 * API调用接口
 */
interface ApiService {
 
    @GET("keywords")
    suspend fun getKeywords():ApiResponse<List<KeywordEntity>>  //异步挂起
}
 
// 创建Retrofit实例(单例)
object RetrofitClient{
 
    private const val BASE_URL ="http://47.96.225.205:9009/cloud/"
 
    //添加Gson解析器,用于自动将JSON响应转换为Kotlin/Java对象
    private val retrofit = Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build()
 
    //通过动态代理技术创建ApiService接口的具体实现类
    val apiService:ApiService = retrofit.create(ApiService::class.java)
 
}