Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
ltttttttttttt committed Mar 12, 2023
1 parent 18711b9 commit 48648e0
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 5 deletions.
21 changes: 21 additions & 0 deletions LazyPeopleHttp-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ group = "io.github.ltttttttttttt"
version = mVersion

kotlin {
android {
publishLibraryVariants("debug", "release")
}

jvm {
compilations.all {
kotlinOptions {
Expand Down Expand Up @@ -59,6 +63,9 @@ kotlin {
}
}

val androidMain by getting
val androidUnitTest by getting

val jvmMain by getting
val jvmTest by getting

Expand All @@ -73,4 +80,18 @@ kotlin {

val jsMain by getting
}
}

android {
compileSdk = 33
defaultConfig {
minSdk = 21
targetSdk = 31
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDir("resources")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
23 changes: 23 additions & 0 deletions LazyPeopleHttp-lib/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright lt 2023
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lt.lazy_people_http">

<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,112 @@
# LazyPeopleHttp

Lazy people http, Retrofit of kmp all targets

Inspired by: https://github.com/ltttttttttttt/retrofit
If you want to use a more functional library, you can use: https://github.com/Foso/Ktorfit

## How to use

Step 1.add dependencies:

version
= [![](https://img.shields.io/maven-central/v/io.github.ltttttttttttt/LazyPeopleHttp)](https://repo1.maven.org/maven2/io/github/ltttttttttttt/LazyPeopleHttp/)

* If it is a single platform, add it to build.gradle.kts in the app module directory

```kotlin
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this,The left 1.7.10 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}

//The fourth step of configuring ksp to generate directory reference links: https://github.com/ltttttttttttt/Buff/blob/main/README.md

dependencies {
...
implementation("io.github.ltttttttttttt:LazyPeopleHttp-lib:$version")//this,such as 1.0.0
ksp("io.github.ltttttttttttt:LazyPeopleHttp:$version")//this,such as 1.0.0
}
```

* If it is multi-platform, add it to build.gradle.kts in the common module directory

```kotlin
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"
}

...
val commonMain by getting {
//Configure the ksp generation directory
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
...
api("io.github.ltttttttttttt:LazyPeopleHttp-lib:$version")//this,such as 1.0.0
}
}

...
dependencies {
add("kspCommonMainMetadata", "io.github.ltttttttttttt:LazyPeopleHttp:$version")
}
```

Step 2.interface declaration:

```kotlin
@LazyPeopleHttpService
interface HttpFunctions {
//Standard post request statement
@POST("post/postB")
fun postB(@Field("name") t: String): Call<NetBean<UserBean>>

//The lazy people post request statement will treat the method name as a url, and its _ will be converted to /
fun post_postC(name: String): Call<NetBean<String>>

//suspend post request statement
suspend fun post_postA(t: String): NetBean<String>

//Standard get request statement
@GET("get/getA")
fun getA(@Query("t") t2: String): Call<NetBean<String>>

//lazy people get request statement
fun get_getB(name: String): Call<NetBean<UserBean>>

//suspend get request statement
suspend fun suspendGetB(name: String): NetBean<UserBean>

//Add static request headers
@Header("aaa", "bbb")
fun post_checkHeader(): Call<NetBean<String?>>

//Configure dynamic urls
@GET("get/getD/{type}")
fun getD(@Url("type") url: String): Call<NetBean<String?>>

//Specific functions can be declared, and no additional methods will be generated at this time
fun ccc(): Int = 0
}
```

Step 3.interface use:

```kotlin
//Configure the client of ktor, the json of serialization
private val client = HttpClient {
defaultRequest {
//Configure baseUrl
url("http://127.0.0.1:666/")
}
}
private val json = Json { ignoreUnknownKeys = true }
private val config = LazyPeopleHttpConfig(client, json)
//Create an implementation class for the request interface
private val hf = HttpFunctions::class.createService(config)

//Implementation class using the interface
hf.postB("123").enqueue()//callback asynchronous request
hf.suspendGetB("111")//Coroutine asynchronous request
```
107 changes: 106 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,112 @@
# LazyPeopleHttp

懒人http客户端,相当于kotlin全平台的Retrofit
相对于Retrofit,有更高的运行时性能,且支持多平台

灵感来源于: https://github.com/ltttttttttttt/retrofit
如果你想使用更多功能的库,可以使用: https://github.com/Foso/Ktorfit

## 使用方式

Step 1.添加依赖:

version
= [![](https://img.shields.io/maven-central/v/io.github.ltttttttttttt/LazyPeopleHttp)](https://repo1.maven.org/maven2/io/github/ltttttttttttt/LazyPeopleHttp/)

* 如果是单平台,在app模块目录内的build.gradle.kts内添加

```kotlin
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this,前面的1.7.10对应你的kotlin版本,更多版本参考: https://github.com/google/ksp/releases
}

//配置ksp生成目录参考链接的第四步: https://github.com/ltttttttttttt/Buff/blob/main/README_CN.md?plain=1

dependencies {
...
implementation("io.github.ltttttttttttt:LazyPeopleHttp-lib:$version")//this,比如1.0.0
ksp("io.github.ltttttttttttt:LazyPeopleHttp:$version")//this,比如1.0.0
}
```

* 如果是多平台,在common模块目录内的build.gradle.kts内添加

```kotlin
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this,前面的1.7.10对应你的kotlin版本,更多版本参考: https://github.com/google/ksp/releases
}

...
val commonMain by getting {
//配置ksp生成目录
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
...
api("io.github.ltttttttttttt:LazyPeopleHttp-lib:$version")//this,比如1.0.0
}
}

...
dependencies {
add("kspCommonMainMetadata", "io.github.ltttttttttttt:LazyPeopleHttp:$version")
}
```

Step 2.接口声明:

```kotlin
@LazyPeopleHttpService
interface HttpFunctions {
//标准post请求声明
@POST("post/postB")
fun postB(@Field("name") t: String): Call<NetBean<UserBean>>

//懒人post请求声明,会把方法名当做url,其下划线会转换为斜杠
fun post_postC(name: String): Call<NetBean<String>>

//suspend post请求声明
suspend fun post_postA(t: String): NetBean<String>

//标准get请求声明
@GET("get/getA")
fun getA(@Query("t") t2: String): Call<NetBean<String>>

//懒人get请求声明
fun get_getB(name: String): Call<NetBean<UserBean>>

//suspend get请求声明
suspend fun suspendGetB(name: String): NetBean<UserBean>

//添加静态的请求头
@Header("aaa", "bbb")
fun post_checkHeader(): Call<NetBean<String?>>

//配置动态的url
@GET("get/getD/{type}")
fun getD(@Url("type") url: String): Call<NetBean<String?>>

//可以声明具体函数,此时不会生成额外的方法
fun ccc(): Int = 0
}
```

Step 3.接口使用:

```kotlin
//配置ktor的client,serialization的json
private val client = HttpClient {
defaultRequest {
//配置baseUrl
url("http://127.0.0.1:666/")
}
}
private val json = Json { ignoreUnknownKeys = true }
private val config = LazyPeopleHttpConfig(client, json)
//创建请求接口的实现类
private val hf = HttpFunctions::class.createService(config)

//使用接口的实现类
hf.postB("123").enqueue()//回调异步请求
hf.suspendGetB("111")//协程异步请求
```
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const val ktorVersion = "2.2.4"//ktor版本
const val serializationJsonVersion = "1.5.0"//json序列号版本
const val kspVersion = "$kotlinVersion-1.0.9"//ksp版本

const val mVersion = "0.0.5"//此库的版本
const val mVersion = "1.0.0"//此库的版本
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
kotlin.code.style=official
kotlin.native.enableDependencyPropagation=false
android.useAndroidX=true
kotlin.version=1.8.0
agp.version=7.2.0
compose.version=1.3.0
xcodeproj=./iosApp
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.native.cocoapods.generate.wrapper=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
Expand Down

0 comments on commit 48648e0

Please sign in to comment.