Skip to content

Creating Interceptor

Once iris mock dependency is configured, you can start creating your custom interceptors.

Creating class

Create a new class implementing the Interceptor interface and annotate it with @IrisMockInterceptor.

Using irisMockScope(chain), all DSL functions will be available:

class MyFirstInterceptor : Interceptor {

    override fun intercept(chain: Chain) = irisMockScope(chain) {
        onGet(endsWith = "/my/endpoint") mockResponse "myCoolJsonResponse"


That's all 😎

Run your app and you should see the following output on logcat:

IrisMock    I    Intercepting: [GET]
IrisMock    I    Mocking Response: [GET]

You can create as many interceptors as you like. It's a good idea to split them according to responsibilities/context, like creating LoginInterceptor, ProfileInterceptor and so on.

Need more examples? take a look at the app sample

If you configured iris mock for a specific build variant, you need to create the classes according.

See more