Giter VIP home page Giter VIP logo

hi-jack-mocker's Introduction

Hi-Jack-Mocker

License Maven Central

🎈 Hi-Jack-Mocker is a project that leverages OkHttp3's interceptor to intercept and modify network requests and responses, allowing you to verify the UI easily.

Request Response

Setup

To integrate Hi-Jack-Mocker into your Android project, follow these steps:

Adding the Dependency

You can add the project dependency using the following code:

debugImplementation("io.github.koreatlwls:hjm:0.1.7")

🚨 Note: This dependency must be added with debugImplementation and should not be included in the release environment.

Initialize Hi-Jack-Mocker in your application:

override fun onCreate() {
    super.onCreate()
    HiJackMocker.initialize(this)
}

Add the above code in the onCreate method of your Application class.

Configure OkHttpClient:

When creating your OkHttpClient instance, include the addHiJackMocker() method
🚨 Note : When using HttpLoggingInterceptor, the order in which interceptors are added is important. You should add addHiJackMocker() first, followed by adding HttpLoggingInterceptor.

@Provides
@Singleton
fun provideHttpClient(): OkHttpClient =
    OkHttpClient.Builder()
        .readTimeout(TEN_SECONDS, TimeUnit.SECONDS)
        .connectTimeout(TEN_SECONDS, TimeUnit.SECONDS)
        .writeTimeout(TEN_SECONDS, TimeUnit.SECONDS)
        .addHiJackMocker()
        .addInterceptor(getLoggingInterceptor())
        .build()

Usage

To enable or disable the Hi-Jack-Mocker mode, use the ImageButton provided at the top of every activity.

This allows you to control whether the hjm mode is active.

Mode Off Mode On

License

Copyright 2024 koreatlwls

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.

hi-jack-mocker's People

Contributors

koreatlwls avatar

Stargazers

Yoon Seong Sik avatar Donghyeon Kim avatar  avatar KwakEuiJin avatar bibbidi avatar Clint Jang avatar wangsu.jang avatar JunHyeong Lee avatar Jiho Lee avatar  avatar Juyoung, Lee avatar jaehyung.jang avatar Park Jong Ho avatar Park, Woocheol avatar  avatar wise_june avatar ezhoon avatar HyunWoo Lee (Nunu Lee) avatar JI HUN LEE avatar 박명범 avatar soopeach avatar

Watchers

Lucian avatar  avatar  avatar

hi-jack-mocker's Issues

UninitializedPropertyAccessException

Issue

HjmInterceptor
kotlin.UninitializedPropertyAccessException: lateinit property ... has not been initialized 

Cause

Hilt performs dependency injection at compile time, so in addHiJackMocker(), it attempts to access an uninitialized object.

Fix header value

Issue

header value is empty

Cause

providing an incorrect value for the header values

Out-of-order responses occur when modifying multiple API requests.

We are using channels to fetch data in multiple interceptors. However, the data retrieval is not in the correct order, and concurrency issues arise. To ensure each request matches its corresponding response, we need to add a UUID value for uniqueness.

We have updated the data type to Pair<String, Response> and switched to using SharedFlow to fetch data from multiple interceptors. This approach resolves both the order and concurrency issues.

Response data loss (2)

Addressing issues related to activity termination and event receive order when handling chained network requests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.