<?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 Vishal Singhal on Medium]]></title>
        <description><![CDATA[Stories by Vishal Singhal on Medium]]></description>
        <link>https://medium.com/@vishal.singhal_54292?source=rss-c86c1391be2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nygzJdqgO8aOoogA</url>
            <title>Stories by Vishal Singhal on Medium</title>
            <link>https://medium.com/@vishal.singhal_54292?source=rss-c86c1391be2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:10:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishal.singhal_54292/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[How to customize KrakenD API Gateway using your own Middlewares?]]></title>
            <link>https://tech.groww.in/how-to-customize-krakend-api-gateway-using-your-own-middlewares-e3b8576f406e?source=rss-c86c1391be2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3b8576f406e</guid>
            <category><![CDATA[spring-cloud-gateway]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[infra]]></category>
            <category><![CDATA[custom-middleware]]></category>
            <category><![CDATA[krakend]]></category>
            <dc:creator><![CDATA[Vishal Singhal]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 08:36:05 GMT</pubDate>
            <atom:updated>2025-04-21T07:16:16.132Z</atom:updated>
            <content:encoded><![CDATA[<p>API Gateway is a standard while creating microservice-based applications. In terms of open-source, <a href="https://threemammals.com/ocelot/">Ocelot</a>, <a href="https://konghq.com/">Kong</a>, <a href="https://tyk.io/">Tyk</a>, <a href="https://spring.io/projects/spring-cloud-gateway">Spring Cloud Gateway</a> are few of the popular gateways. While looking for the fastest and most reliable API Gateway, I came across <a href="https://www.krakend.io/">KrakenD</a>. On KrakenD’s website, we can see performance comparison with Kong and Tyk. The difference is pretty amazing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alos4_ecpWr_JItU9KrKXA.png" /><figcaption>KrakenD vs other products in the market. Requests per second inequal conditions. <a href="https://www.krakend.io/docs/benchmarks/overview/">See benchmarks</a></figcaption></figure><p><strong>So, what is KrakenD?</strong></p><p>KrakenD is a <a href="https://www.krakend.io/features/">stateless</a>, distributed, linearly scalable, high-performance API Gateway. KrakenD has a powerful engine that can transform, aggregate, or remove data from your own service or third-party services. It is written in GoLang.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbqM0MOY7nGR31UsEvAE1A.png" /><figcaption>KrakenD API Gateway on commodity hardware</figcaption></figure><p>Before diving deep into creating our own customize KrakenD API Gateway, let’s understand middlewares.</p><p><strong>What is a Middleware?</strong></p><p>A <strong>middleware handler</strong> is simply an http.Handler that wraps another http.Handler to do some pre- and/or post-processing of the request. It’s called “middleware” because it sits in the middle between the Go web server and the actual handler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzWJ5OiY9m8wZl7gXUQ5Bg.png" /><figcaption>Request &amp; Response flow with Middleware</figcaption></figure><p>There could be N number of middlewares inside KrakenD Api gateway as per our requirements.</p><p>Some of the use cases where you want to add your custom middleware are:</p><ul><li><strong>Monitoring traffic</strong>: Logging and building statistics.</li><li><strong>Security</strong>: Adding your own customized security check before sending a request to the backend.</li><li><strong>Caching</strong>: Caching headers.</li><li><strong>Throttling</strong>: Rate limiting to save your infra from shut down.</li><li>Request &amp; Response manipulation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N8DQvCcz4UMTjDa_aGEftw.png" /></figure><p>KrakenD Community Edition (or <a href="https://github.com/devopsfaith/krakend-ce">Krakend-CE</a> ) is the binary distribution of KrakenD. Krakend-CE is an Ultra-High performance API Gateway with middlewares.</p><p>We will start writing custom middleware and integrate it inside krakend-ce. Let’s Assume that, we want to match the API key sent inside<strong> </strong>the<strong> Authorization </strong>header.</p><p><strong>Prerequisites</strong></p><ul><li>Go 1.5 or above installed.</li><li>Basic understanding of <a href="https://www.krakend.io/">KrakenD</a></li></ul><p><strong>Assumptions</strong></p><ul><li>We will be using the default http router(<a href="https://github.com/gin-gonic/gin">go-gin</a>) integrated into KrakenD. If you want to use any other http router you need to change it before starting to write the custom middleware.</li></ul><p><strong>Basic Setup</strong></p><ul><li>Clone the <a href="https://github.com/devopsfaith/krakend-ce">Krakend-CE</a> in your local machine. Check for packages inside go.mod file which is required for you and remove the extra ones.</li><li>Restructure your project by moving .go extension files inside a new folder. This will help you separate your custom middleware logic.</li><li>If you want to take a reference or avoid the above two steps you can clone it from <a href="https://github.com/Singhal-vishal/krakend-custom-middleware/tree/base_code">here</a>.</li><li>Now build the krakend-ce using</li></ul><pre>go build</pre><ul><li>After building it, refresh the krakend-ce folder, you can see a binary file created named kranked-ce, run the krakend-ce using</li></ul><pre>./krakend-ce run -d -c ./config/krakend.json</pre><ul><li>After successfully running it should be like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*moUJRn9faFyxIlVUpKSU0w.png" /></figure><ul><li>Run <a href="http://locahost:9001/__health">this</a> to check if everything is working 😃</li></ul><p>Now our basic setup is done, we can start writing our middleware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Uoc0edU_DZXadKNytJkOA.png" /></figure><ul><li>Above is the middleware to match the API key sent in the request inside the <strong>Authorization</strong> header.</li><li>Create a new package, this package will contain your all custom logic(In the above example it is named <strong>internal)</strong></li><li>If the API key does not match with the <strong>Authorization</strong> it throws 401(Unauthorized)</li><li><strong>c.Next()</strong> sends a request to the next middleware since in our case there is no extra middleware, KrakenD will send the request to downstream service.</li></ul><p>The next step is to initialize middleware in main.go and call it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GtFrIRRtj-AhKqLwRwqng.png" /></figure><ul><li>Now build and run.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9MIfq7Nml8jVcsfMKw4cA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WG37fe7oQjeukdJJgwSg1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6CduGODmvn8vJzB2qDg9Q.png" /></figure><p><strong>API Request Flowchart</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtmAfOQy_sCeS1JUmorEKQ.png" /></figure><p><strong>Note</strong></p><ul><li>Similarly, we can write any custom logic we require and add <em>n</em> number of middlewares.</li><li><a href="https://github.com/Singhal-vishal/krakend-custom-middleware/tree/base_code">Github Repository Link</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3b8576f406e" width="1" height="1" alt=""><hr><p><a href="https://tech.groww.in/how-to-customize-krakend-api-gateway-using-your-own-middlewares-e3b8576f406e">How to customize KrakenD API Gateway using your own Middlewares?</a> was originally published in <a href="https://tech.groww.in/">The Groww Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>