-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small improvements & README file (#49)
* return custom response instead of the real call response; add README file * Update build.gradle * Update build.gradle * Update build.gradle --------- Co-authored-by: Eugene Tkachenko <[email protected]>
- Loading branch information
1 parent
174aae8
commit 187a1cb
Showing
6 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Request Modifier is a new Android library designed to provide developers with an easy way to | ||
customize HTTP responses. | ||
By adding this library into your project, you gain the ability to modify response bodies and | ||
response codes dynamically. | ||
|
||
| <img src="https://github.com/itkacher/OkHttpProfiler/blob/master/request_modifiers_activity.png?raw=true"> | <img src="https://github.com/itkacher/OkHttpProfiler/blob/master/request_modifiers_add_new_modifier.png?raw=true"> | | ||
|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------| | ||
|
||
## Installation | ||
|
||
For installation, you need to include the library to your app build.gradle file | ||
|
||
releaseImplementation 'io.nerdythings:okhttp-requests-modifier-no-op:1.1.0' | ||
debugImplementation 'io.nerdythings:okhttp-requests-modifier:1.0.0' | ||
|
||
and add Interceptor to okHttpClient in code | ||
|
||
##### For OkHttp | ||
|
||
val builder = OkHttpClient.Builder() | ||
if (BuildConfig.DEBUG) { | ||
builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext)) | ||
} | ||
val client = builder.build() | ||
|
||
##### For Retrofit | ||
|
||
val builder = OkHttpClient.Builder() | ||
if (BuildConfig.DEBUG) { | ||
builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext)) | ||
} | ||
val client = builder.build() | ||
val retrofit = Retrofit.Builder() | ||
...... | ||
.client(client) | ||
.build() | ||
|
||
##### For security reasons we recommend to enable OkHttpProfilerInterceptor only for DEBUG BUILDS! | ||
|
||
Also Proguard will cut it out in the release build. | ||
|
||
## Customization Capabilities | ||
|
||
With the Request Modifier, you can adjust the response body and response code for your HTTP | ||
requests. | ||
Additionally, the library supports the use of regular expressions (regex) to match and modify | ||
multiple requests at once, offering a powerful and flexible way to handle different scenarios. | ||
|
||
Important: if you override request, it won't make a real call, it'll immediately return your custom | ||
data. | ||
|
||
## Usage | ||
|
||
To define custom responses, follow these steps: | ||
|
||
1. Add the library to your project and set up the custom interceptor as shown above. | ||
2. Access the built-in Activity from your debug menu, which provides a user-friendly interface for | ||
managing your requests. | ||
3. Through this Activity, you can easily add and modify your requests, specifying the desired | ||
response bodies and response codes. | ||
|
||
This intuitive UI makes it straightforward for developers to define and manage custom responses | ||
without diving deep into the code, enhancing productivity and debugging efficiency. |