bruce3x / APIMock

Mock API data for Android Apps.

Home Page:https://github.com/brucezz/APIMock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

APIMock

Mock API data simply with OkHttp.

Installation

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

	dependencies {
        compile 'com.github.brucezz:APIMock:v1.0.1'
	}

or

	dependencies {
        compile 'com.github.brucezz:APIMock:v1.0.1'{
           exclude group:'com.squareup.okhttp3'
       }
	}

Usage

Step 1. Add MockInterceptor to your OkHttpClient

    mHttpClient = new OkHttpClient().newBuilder()
        // ...something 
        .addInterceptor(new MockInterceptor())
        .build();

Step 2. Create your config file config.json

Default format:

{
    "base": "http://gank.io/api",
    "delay": 1000, 
    "remote": "/storage/emulated/0/APIMock", 
    "route": {
    	"/data/Android/\\d+/\\d+":"mock/gank.json"
    }
}
  • "remote" : location of config files on Android device
  • "base" : api host
  • "delay" : imitate network delay time
  • "route" : mock rules
  • key : the path of API URL
  • value : mock data file (JSON)

Step 3. Create mock data files

Mock files are JSON files including different response data.

Put your mock files in mock directory.

Step 4. Push your config files to Android device

A command-line utility is provided -- APIMockHelper.

And you can use whatever tools you want :)

Done, enjoy it!

More detail see the sample please.

Screenshots

First, click the 'GET' to send network request.

step1

Then, create my mock data, push to device.

step2

Finally, make the same request but response changed.

step3

Credit

Thanks for Gank.io API.

About

Mock API data for Android Apps.

https://github.com/brucezz/APIMock


Languages

Language:Java 100.0%