Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WotCore/Http-ktx

Repository files navigation

API

Http-ktx

DSL网络请求框架

第一步 先写个 ApiService

@GET("/banner/json")
suspend fun getBanner(): Response<List<Banner>>

第二步 创建 Service实例

val apiService: ApiService by lazy {
 HttpBuilder.createService(
 "https://www.wanandroid.com",
 okClientAction = {
 // OkHttpClient.Builder
 },
 retrofitAction = {
 // Retrofit.Builder
 }
 )
}

第三步 数据获取

 val liveData = viewModelScope.requestData {
 // 请求网络
 api {
 wanAndroidService.getBanner()
 }
 // 加载数据缓存
 loadCache {
 }
 // 将数据保存到数据库
 saveCache {
 }
 }

引入

添加仓库

在项目的 build.gradle 文件中配置仓库地址。

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

添加项目依赖

在需要添加依赖的 Module 下添加以下信息,使用方式和普通的远程仓库一样。

implementation 'com.github.WotCore:Http-ktx:v1.0.1'

AltStyle によって変換されたページ (->オリジナル) /