一键导入
basekit-network
Complete guide for BaseKit Network module, including Coroutines support (KCHttp), error handling, HTTPS, SSE, and caching strategies.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Complete guide for BaseKit Network module, including Coroutines support (KCHttp), error handling, HTTPS, SSE, and caching strategies.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Koog 开发工具包:梳理 Tools/MCP/Prompt/LLM 参数/记忆/压缩/审核等规范并产出模板。用户提到 Koog、ToolRegistry、MCP、AskUser、ChatMemory 时调用。
将当前分支重组为一组小而清晰、适合代码评审的语义化提交。用户要求拆分提交、整理 commit 历史、重做提交顺序时调用。
Expert guidance on setting up scalable Gradle build logic using Convention Plugins and Version Catalogs.
Solutions for common Android Gradle build errors. Invoke when encountering build failures, duplicate file conflicts, manifest merger issues, or dependency resolution errors.
Guide for Jetpack Navigation 3 in Compose. Invoke when user asks to set up Navigation 3, manage back stack, or use NavDisplay.
Guide for kotlinx.serialization in Kotlin/Android. Invoke when user asks about JSON parsing, serialization, deserialization, or setting up Kotlin Serialization.
| name | basekit-network |
| description | Complete guide for BaseKit Network module, including Coroutines support (KCHttp), error handling, HTTPS, SSE, and caching strategies. |
BaseKit 的网络层由 me.shetj.base.network(基础组件)和 me.shetj.base.netcoroutine(协程封装)两个核心模块组成。它提供了从底层配置到上层业务调用的完整解决方案。
me.shetj.base.netcoroutine 模块是基于 Kotlin 协程和 Ktor Client 的高级封装,是日常开发中的主要入口。
KCHttp)KCHttp 单例对象提供了 GET、POST (Form/Json/Body) 等常用方法。
val result = KCHttp.get<User>(
url = "https://api.example.com/user",
maps = mapOf("id" to "123"),
requestOption = RequestOption(cacheMode = CacheMode.FIRST_NET)
)
val result = KCHttp.postJson<ApiResponse>(
url = "https://api.example.com/update",
json = "{\"name\":\"test\"}",
requestOption = RequestOption(timeout = 5000)
)
RequestOption)精细控制请求行为:
CacheMode)DEFAULT: 仅使用 OkHttp 标准缓存。FIRST_NET: 优先网络,失败后读缓存。FIRST_CACHE: 优先缓存,无缓存读网络。ONLY_NET: 仅网络(更新缓存)。ONLY_CACHE: 仅缓存。CACHE_NET_DISTINCT: 先返缓存,后台请求网络,数据变化则再次返回(需配合 LiveData/Flow)。HttpResult<T> (Success/Failure/Loading)。
KCHttp.get<User>(...).fold(
onSuccess = { user -> ... },
onFailure = { error -> ... }
)
KCHttp.download(url, outputFile,
onProcess = { cur, total, prog -> ... },
onSuccess = { file -> ... }
)
me.shetj.base.network 模块提供了底层支持,如异常处理、安全配置和拦截器。
ApiException)将所有异常统一为 ApiException。
try {
// request
} catch (e: Throwable) {
val error = ApiException.handleException(e)
// error.code, error.message
}
HttpsUtils)便捷配置 SSL 证书(单向/双向认证)。
val sslParams = HttpsUtils.getSslSocketFactory(null, null, arrayOf(certStream))
OkHttpClient.Builder()
.sslSocketFactory(sslParams.sSLSocketFactory!!, sslParams.trustManager!!)
HttpLoggingInterceptor)支持 JSON 格式化输出和文件导出的日志拦截器。
val logger = HttpLoggingInterceptor("Tag").setLevel(Level.BODY)
OkHttpClient.Builder().addInterceptor(logger)
SseClient)基于 OkHttp 的 Server-Sent Events 实现。
SseClient.start(url)
lifecycleScope.launch {
SseClient.shareFlow.collect { msg -> ... }
}
OkHttpDns)防 DNS 劫持,支持自定义 IP 映射。
OkHttpClient.Builder().dns(OkHttpDns.getInstance())
KCHttp.kt: 统一入口。cache/: LRU 磁盘缓存实现。RequestOption.kt: 请求配置。exception/: 异常定义。https/: 证书配置。interceptor/: 拦截器。sse/: SSE 客户端。