A kotlin tool to intercept android network calls, modify requests/responses and mock entire APIs. Also includes a cool DSL, that helps to reduce boilerplate code and simplify development.
btw, Iris is my daughter's name 🥰
- Works with Retrofit, Volley and every libs that depend on OkHttp
- Allow intercept call on 3rd-party libs
- DSL to avoid boilerplate
- A centralized tool to log, intercept and modify requests/response
- As it works at bytecode level, can be used with 3rd-party libs
- No need to apply KAPT or KSP, since it's implemented directly through KCP
- No need to do SSL things, like inject certificate
plugins {
id("dev.arildo.iris-mock-plugin") version "1.1.0"
}
Using legacy plugin application - older gradle
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("dev.arildo:iris-mock-plugin:1.1.0-alpha04")
}
}
apply(plugin = "dev.arildo.iris-mock-plugin")
Just create a class implementing the Interceptor
interface and annotate it with @IrisMockInterceptor
. That's all. The interceptor will be automatically injected at OkHttp
@IrisMockInterceptor
class MyInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain) = irisMock(chain) {
enableLogs() // you can log requests
onGet(contains = "user/profile") mockResponse userProfileJson
onPost(endsWith = "/login") {
delay(2_000)
if (containsInRequestBody("validPassword")) mockResponse(successLoginJson)
else mockResponse(errorPasswordJson)
}
}
}
See official docs for further details
- Add support to Ktor
- Expand DSL
- and many other cool things
Feel free to open PRs and submit feature suggestions via the repository issues. Everything's welcome 😎
Copyright 2023 Arildo Borges Junior
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.