Skip to content

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.

License

Notifications You must be signed in to change notification settings

ujizin/iris-mock

Repository files navigation



ktlint

A kotlin-first 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

Features

  • Works with Retrofit, Volley and every libs that depend on OkHttp
  • Allow intercept call on 3rd-party libs
  • DSL to avoid boilerplate

Why use iris mock?

  • A centralized tool to log, intercept and modify requests/response
  • As it works at bytecode level, can be used with 3rd-party libs
  • Compiler developed using KSP, up to 2x faster than KAPT
  • No need to do SSL things, like inject certificate

How to use

Dependencies

// add plugin to app module build.gradle.kts
plugins {
    id("com.google.devtools.ksp")
    id("dev.arildo.iris-mock-plugin") version "1.0.1"
}

// add dependencies
dependencies {
    implementation("dev.arildo:iris-mock:1.0.1")
    ksp("dev.arildo:iris-mock-compiler:1.0.1")
}

Code

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) = irisMockScope(chain) {
        onGet(contains = "user/profile") mockResponse userProfileJson
        onPost(endsWith = "/login") then {
            delay(2_000) // supports coroutine 
            if (requestContains("validPassword")) mockResponse(successLoginJson)
            else mockResponse(errorPasswordJson)
        }
        startLogger() // you can log requests
    }
}

See official docs for further details

Roadmap

  • Add support to Ktor
  • Expand DSL
  • and many other cool things

Contributing

Feel free to open PRs and submit feature suggestions via the repository issues. Everything's welcome 😎

Support

"Buy Me A Coffee"

License

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.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%