An OkHttp interceptor to intercept and manipulate response at runtime

Overview

NetworkProxy Download Build Status

A network proxy library to intercept and mock response from OkHttp

Getting started

In your root build.gradle:

allprojects {
    repositories {
        // Other configurations ...
        jcenter()
    }
}

In your app/build.gradle:

dependencies {
  debugImplementation 'com.github.nongdenchet:networkproxy:0.7.0'
  releaseImplementation 'com.github.nongdenchet:networkproxy-no-op:0.7.0'
}

Since OkHttp now requires Android 5.0+ (API level 21+) and Java 8+, we need to add:

android {
  // other configuration...
  defaultConfig {
    // other configuration...
    minSdkVersion 21
  }
  
  // other configuration...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Add the Interceptor to your OkHttp builder:

new OkHttpClient.Builder()
  // other configuration...
  .addInterceptor(NetworkProxy.interceptor())
  // other configuration...
  .build();

Using with desktop app

  • In your Application class:
public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    NetworkProxy.init(this, 9000); // 9000 is the port that is later use to connect from Desktop app
    // Normal app init code...
  }
}
  • Connect your device with adb and run adb forward tcp:8000 tcp:9000 to connect port 8000 of your computer and port 9000 of your device
  • We provide a client desktop app to use and interact with pending response
  • Demo: alt text

Using without desktop app

  • In your Application class:
public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    NetworkProxy.init(this);
    // Normal app init code...
  }
}
  • To mock data from a pending response
adb shell "am broadcast -a com.rain.networkproxy.INSTRUCTION -n [YOUR_APP_PACKAGE]/com.rain.networkproxy.NPReceiver \
    --es data '{"id": "0", "status": 200}' \
    --es body '"'{"id": 1, "title": "hello"}'"'"

"id": "0" is the pending response id. You can get it through the UI or from Logcat (Put NetworkProxy as filter to see the logs)

  • Demo: alt text

License

Copyright 2018 Quan Vu.

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.
You might also like...
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

Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manipulating application data on-the-go.
Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manipulating application data on-the-go.

Pluto Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manip

A gRPC Kotlin based server and client starter that builds with Gradle and runs on the JVM
A gRPC Kotlin based server and client starter that builds with Gradle and runs on the JVM

gRPC Kotlin starter Overview This directory contains a simple bar service written as a Kotlin gRPC example. You can find detailed instructions for bui

A product registration service using the Kotlin language and the Micronaut and Grpc framework
A product registration service using the Kotlin language and the Micronaut and Grpc framework

A product registration service using the Kotlin language and the Micronaut and Grpc framework

Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

Android Asynchronous Networking and Image Loading
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Owner
Quan Vu
Quan Vu
Sandwich was invented for constructing the standardized response interface from the network response

?? A lightweight and standardized Android network response interface for handling successful data and error responses.

Jaewoong Eum 973 Jan 5, 2023
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
A small Android project to practice executing network requests and parsing the network response

InspirationalQuotesExercise A small Android project to practice executing network requests and parsing the network response This app uses the ZenQuote

Caren 0 Oct 13, 2021
TART: Tracing Action Response Times

Square Tart Tracing Action Response Times! This library is not stable for usage beyond Square, the APIs and internals might change anytime. Tart... ?

Square 246 Nov 24, 2022
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
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
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 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