A simple okhttp interceptor to mock api's

Overview

mockp-interceptor

Mockp-interceptor is a library to simplify Android development requests that uses Retrofit and OkHttp. This library will mock requests using a json file format in assets folder.

Basically you need to put a simple annotation in Retrofit Service with file path, status code (optional, default is 200) and run delay (optional, default is false).

Getting started

Mockp-Interceptor is distributed through jitpack. You need to add dependency in build.gradle file and pay attention in two libraries variants:

  • library: used in development mode, will mock requests.
  • library-no-op: used in release mode, will not mock requests, is just a fake interceptor that repass the requests forward.
dependencies {
    releaseImplementation 'com.github.brunogabriel.mockp-interceptor:library-no-op:0.0.1'
    debugImplementation 'com.github.brunogabriel.mockp-interceptor:library:0.0.1'
}

Do not forget to add jitpack configuration too:

allprojects {
    repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Thank you Chucker and Chuck. I learnt this approach to no-op interceptors long time ago by using both libraries.

Configure

It is easy to configure Mockp, just pass context in Builder pattern and optional value if you need to simulate delay. Default delay is between 0 and 1000 milliseconds.

// Create interceptor
val mockpInterceptor = MockPInterceptor
    .Builder(context)
    .addDelayInMillis(5_000L, 10_000L)
    .build()

// Plug in OkHttpClient
val client = OkHttpClient
    .Builder()
    .addInterceptor(mockpInterceptor)
    .build()

How to use it in development

Create assets folder and pass a json file path, for example, response.json, then:

@MOCK(asset = "response.json", runDelay = true)
@GET("products")
suspend fun getProducts(): List<Product>

Libraries

Mockp-Interceptor uses the following open source libraries:

License

See LICENSE

You might also like...
super simple library to manage http requests.

HttpAgent super simple library to manage http requests. Gradle dependencies { implementation 'com.studioidan.httpagent:httpagent:1.0.16@aar' } No

Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App
Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App

WaterLevel Preface This project aims to finding a tanker water level using NodeMCU with ESP8266 core and HC-SR04P Ultrasonic sensor and broadcasting i

Very simple SMS to API gateway

sms2api Very simple SMS to API gateway for Android devices. It's NOT Google Play compatible, due to the security restrictions but it works well on you

Simple kafka client for monitoring topic events. Client has UI powered by Darklaf
Simple kafka client for monitoring topic events. Client has UI powered by Darklaf

kafka-client Simple kafka client for monitoring topic values. How to start $ java -jar kafka-client-1.0.jar How to use specify kafka hosts in config.y

Uppics - A simple app that authenticates a user and allows them to post images which can then be upvoted or downvoted
Uppics - A simple app that authenticates a user and allows them to post images which can then be upvoted or downvoted

UpPics A simple app that authenticates a user and allows them to post images whi

Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin
Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin

Kotlin REST Retrofit Sencillo cliente para consumir una API REST con Retrofit us

MVVM with simple HTTP Request Example
MVVM with simple HTTP Request Example

Minimum MVVM Koin (Kotlin Dependency Injection) Coroutines View Model Lifecycle News API Retrofit Rx Java Rx Android OkHttp Client Result ScreenShot 1

An OkHttp interceptor which has pretty logger for request and response. +Mock support
An OkHttp interceptor which has pretty logger for request and response. +Mock support

LoggingInterceptor - Interceptor for OkHttp3 with pretty logger Usage val client = OkHttpClient.Builder() client.addInterceptor(LoggingInterceptor

Customizable OkHttp Logging Interceptor

An OkHttp interceptor which logs HTTP request and response data and allows output customization.

Mock your datas for Okhttp and Retrofit in json format in just a few moves

okhttp-json-mock This simple library helps you mock your data for using with okhttp+retrofit in json format in just a few moves. it forwards the reque

Wiremock-testing - WireMock - A great library to mock APIs in your tests and supports Junit5
Wiremock-testing - WireMock - A great library to mock APIs in your tests and supports Junit5

WireMock Testing WireMock is a great library to mock APIs in your tests and supp

Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor
Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor

Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor and so much more...

Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.
Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.

1. AutoProxy Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a

Android library to record the network calls through the interceptor mechanism of the http clients.
Android library to record the network calls through the interceptor mechanism of the http clients.

Android Snooper Introduction Android Snooper is a library which helps in debugging issues while running the applications on android devices. One of th

Trying to play with Jetpack compose low level animations APIs, which are animate*AsState APIs.
Trying to play with Jetpack compose low level animations APIs, which are animate*AsState APIs.

ComposeSimpleAnimation Trying to play with Jetpack compose low level animations APIs, which are animate*AsState APIs that I needed in another project.

NiceHttp - A small and simple OkHttp wrapper to ease scraping

NiceHttp - A small and simple OkHttp wrapper to ease scraping

Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock
Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock

This kata is a Kotlin multiplatform version of the kata KataTODOApiClientKotlin of Karumi. We are here to practice integration testing using HTTP stub

Lightweight service for creating standalone mock, written in pure Kotlin with Netty container.

MockService The lightweight service for creating a standalone mock, written in pure Kotlin with Netty container. The service allows getting config fil

Using grpc-wiremock to mock responses in integrated tests of gRPC services
Using grpc-wiremock to mock responses in integrated tests of gRPC services

Utilizando grpc-wiremock para mockar respostas em testes integrados de serviços gRPC Este repositório possui um exemplo prático de como configurar e r

Releases(0.0.1)
Owner
Bruno Gabriel dos Santos
If you're afraid to fail, then you're probably going to fail. ☕️🇧🇷
Bruno Gabriel dos Santos
Mock your datas for Okhttp and Retrofit in json format in just a few moves

okhttp-json-mock This simple library helps you mock your data for using with okhttp+retrofit in json format in just a few moves. it forwards the reque

Mad Mirrajabi 240 Nov 25, 2022
NiceHttp - A small and simple OkHttp wrapper to ease scraping

NiceHttp - A small and simple OkHttp wrapper to ease scraping

LagradOst 19 Dec 17, 2022
SimpleInterceptor for okhttp

SimpleInterceptor Simpleinceptor is the interception interface tool of Android okhttp client, which is convenient for testing or development and quick

zhonghua 25 Jun 21, 2022
A "fluent" OkHTTP library for Kotlin based on string extensions.

okfluent A "fluent" OkHTTP library for Kotlin based on string extensions. Do not take this project seriously, I just wanted to show that this kind of

Duale Siad 0 Nov 23, 2021
A basic list application designed using MVVM pattern with Retrofit, OkHttp, and Hilt for dependency injection

FRExercise A basic list application designed using MVVM pattern with Retrofit, O

null 0 Dec 22, 2021
A Beautiful Log Printer For OkHttp.

LogDog A Beautiful Log Printer For OkHttp. It looks like this: Import repositories { maven { url 'https://jitpack.io' } } //something else... impl

Michael Lee 3 Jun 21, 2022
SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network requests with HttpURLConnection.

SimpleApiCalls ?? SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network reque

null 4 Nov 28, 2022
IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

Anton Nurdin Tuhadiansyah 61 Jun 24, 2022
HttpMocker is a simple HTTP mocking library written in Kotlin to quickly and easily handle offline modes in your apps

HttpMocker HttpMocker is a very lightweight Kotlin library that allows to mock HTTP calls relying on either OkHttp or the Ktor client libraries. It ca

David Blanc 174 Nov 28, 2022
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022