<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hanna on Medium]]></title>
        <description><![CDATA[Stories by Hanna on Medium]]></description>
        <link>https://medium.com/@sunhumann2010?source=rss-91d9228e0749------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*y6kmhYNxGBYj_OTOIyAGaQ.jpeg</url>
            <title>Stories by Hanna on Medium</title>
            <link>https://medium.com/@sunhumann2010?source=rss-91d9228e0749------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:17:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunhumann2010/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fast and easy way to modify HTTP response for your application]]></title>
            <link>https://proandroiddev.com/fast-and-easy-way-to-modify-http-response-for-your-application-4efbef997188?source=rss-91d9228e0749------2</link>
            <guid isPermaLink="false">https://medium.com/p/4efbef997188</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[okhttp]]></category>
            <dc:creator><![CDATA[Hanna]]></dc:creator>
            <pubDate>Wed, 07 Aug 2024 01:15:35 GMT</pubDate>
            <atom:updated>2024-08-10T04:28:46.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDCVRRmK_SRgSHv_ugLYBA.jpeg" /></figure><p>If you’re an Android developer, you might have faced times when you’re building a new feature, but the API you need isn’t ready yet. Or maybe you need to test different scenarios with various API responses. In these cases, you need a tool that makes it easy to change or replace HTTP responses for your app.</p><p>To handle these situations, you need something simple that lets you customize or fully change HTTP responses. When you search for tools, you’ll probably find popular ones like Charles or Requestly. These tools are great, but they have a big downside: they’re complicated to set up with proxies and certificates.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FTrGYjPizNAQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTrGYjPizNAQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTrGYjPizNAQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a28a679fe22a70cd73ddc526fb18c900/href">https://medium.com/media/a28a679fe22a70cd73ddc526fb18c900/href</a></iframe><h3>OkHttp Request Modifier Android Library</h3><p>That’s where the <a href="https://github.com/itkacher/OkHttpProfiler/tree/master/okhttp-requests-modifier">OkHttp Request Modifier</a> comes in. This easy-to-use Android library lets you change HTTP responses without all the setup hassle. By adding the Request Modifier to your project, you can easily modify response bodies and response codes as needed.</p><p>In this article, we’ll explore how Request Modifier works, its main features, and how you can use it to make your development process smoother and more efficient.</p><h4>Installation</h4><p>For the installation, you need to include the library in your app module’s build.gradle file</p><pre>releaseImplementation &#39;io.nerdythings:okhttp-requests-modifier-no-op:1.0.1&#39;<br>debugImplementation &#39;io.nerdythings:okhttp-requests-modifier:1.0.1&#39;</pre><p>and add an Interceptor to the <em>OkHttpClient</em> in the code</p><pre>// for OkHttp<br>val builder = OkHttpClient.Builder()<br>if (BuildConfig.DEBUG) {<br>    builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))<br>}    <br>val client = builder.build()<br><br><br>// for Retrofit<br>val builder = OkHttpClient.Builder()<br>if (BuildConfig.DEBUG) {<br>    builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))<br>}    <br>val client = builder.build()<br>val retrofit = Retrofit.Builder()<br>        ......<br>        .client(client)<br>        .build()</pre><p>For security reasons, I recommend enabling this interceptor only for <strong>DEBUG builds</strong>! Also, Proguard will cut it out in the release build.</p><h4>Plugin capabilities</h4><p>With the <em>Request Modifier</em>, you can easily change the response body and response code of your HTTP requests. The library even supports regular expressions (regex), allowing you to match and modify multiple requests at once. This gives you a flexible way to handle various scenarios.</p><p><strong>Important:</strong> If you override a request, it won’t make a real call. Instead, it will immediately return your custom data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AmfLMprPbUtyhcK3Sn0sZg.png" /><figcaption>Request with a custom response in the OkHttp Profiler</figcaption></figure><h4>Usage</h4><p>To define custom responses, follow these steps:</p><ol><li><strong>Add the Library:</strong> Include the library in your project by updating your build.gradle file.</li><li><strong>Set Up the Interceptor:</strong> Set up the custom interceptor as described above.</li><li><strong>Access the Built-in Activity:</strong> From your debug menu, access the built-in Activity, which offers a user-friendly interface for managing your requests.</li><li><strong>Add and Modify Requests:</strong> This Activity lets you easily add and modify your requests, specifying the desired response bodies and codes.</li></ol><pre>class MainActivity : AppCompatActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContent {<br>            Column(<br>                verticalArrangement = Arrangement.Center,<br>                horizontalAlignment = Alignment.CenterHorizontally,<br>                modifier = Modifier.fillMaxSize(),<br>            ) {<br>                ...<br>                Button(onClick = ::openSettings) {<br>                    Text(text = stringResource(id = R.string.open_modifier))<br>                }<br>                ...<br>            }<br>    }<br><br>    private fun openSettings() {<br>        startActivity(OkHttpProfilerSettingsActivity.getIntent(applicationContext))<br>    }<br><br>    ...<br>}</pre><p>The intuitive UI makes it easy for developers to define and manage custom responses without diving deep into the code, boosting productivity and making debugging more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*46vpsfEzq9rCFP9ofWy3gQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*XqbzRz5tQvTBSC7rjbqFOw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4efbef997188" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/fast-and-easy-way-to-modify-http-response-for-your-application-4efbef997188">Fast and easy way to modify HTTP response for your application</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>