<?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 Mike Tcholakian on Medium]]></title>
        <description><![CDATA[Stories by Mike Tcholakian on Medium]]></description>
        <link>https://medium.com/@miketcholakian?source=rss-330950b89266------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kaVdO5iEOIxJb6rKAtRU3w.jpeg</url>
            <title>Stories by Mike Tcholakian on Medium</title>
            <link>https://medium.com/@miketcholakian?source=rss-330950b89266------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:50:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miketcholakian/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[Middlewares in React]]></title>
            <link>https://miketcholakian.medium.com/middlewares-in-react-a24e33780791?source=rss-330950b89266------2</link>
            <guid isPermaLink="false">https://medium.com/p/a24e33780791</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[patterns]]></category>
            <dc:creator><![CDATA[Mike Tcholakian]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 00:13:15 GMT</pubDate>
            <atom:updated>2021-04-03T00:13:15.435Z</atom:updated>
            <content:encoded><![CDATA[<p>How to intercept calls to external services with middlewares and make it flexible enough to quickly change target environment.</p><p>So you probably have worked with middlewares or at least have an idea of how they work.</p><blockquote><em>Ok, basically a </em><strong><em>middleware</em></strong><em> is a piece of software which connects two applications and make data flow through them. There are different types of middlewares, but for the purpose of the article let’s focus on web middlewares.</em></blockquote><p>If you are familiar with <a href="https://expressjs.com/es/">express</a> and you are implementing your custom middleware you could see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*_8K54ioTvsx-E5t39EZAYA.png" /></figure><p>Ok, basically this middleware accepts three parameters: req, res and next.</p><p>The middleware has the ability to transform either the incoming value (req) or the outcoming one (res) and pass the control to the next middleware (next).</p><blockquote>So a middleware can be used for example to modify all your incoming requests in one singe place or implement some central authentication mechanism. Pretty good, right?</blockquote><p>These middlewares are chained. They run one after the other. So if you don’t call the next one then your execution flow is aborted.</p><p>So…let’s start with the React part, ok? I’ve implemented a really simple project which illustrates this architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*77wkO0GutqAJt0m3fzBB3Q.png" /></figure><p>I guess you are familiar with redux management state and data flow through it. As you can see above there is a small piece, called “middleware” which intercepts some actions, makes external api calls and dispatches new actions with the result. Interesting…</p><p>Ok…show me an example, I’m tired of reading :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*Ome7H-TfyaOoHDKYbxDItw.png" /></figure><p>Ok…this middleware is taking a LOAD_POSTS action from the UI, dispatching a new action for UI for a loading status and <strong>also making an external service call.</strong></p><p>See how we decoupled our UI and infraestructure layer? Now the middleware is in charge of making this service calls. When the results comes we simply update the UI.</p><p>Let’s go deeper and see how it is implemented on index.js:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*WZiimM72_hyn_FjkWNjWMg.png" /></figure><p>And now, the interesting part…How we setup this store on Provider node:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*P-z4KMmW_QJhGI0pCrn7Xw.png" /></figure><p>Finally our services have this implementation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*nhTjeZj46izh3eLIGBa3wA.png" /></figure><p>These are the services that were injected to the configureStore on the Provider node on index.js</p><p>See how depending on our environment we can easily switch to a mock implementation of our service or a real one.</p><p>I hope you like my first article.<br>I leave my <a href="https://github.com/chorli/reactCleanArchitecture">github repository </a>with a working sample. Cheers :)!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a24e33780791" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>