<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>API on Melchi</title><link>https://melchi.me/tags/api/</link><description>Recent content in API on Melchi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 17 May 2026 12:00:00 +1000</lastBuildDate><atom:link href="https://melchi.me/tags/api/index.xml" rel="self" type="application/rss+xml"/><item><title>Rate limiting in Golang HTTP client</title><link>https://melchi.me/posts/golang/</link><pubDate>Sun, 01 Dec 2019 21:57:40 +0800</pubDate><guid>https://melchi.me/posts/golang/</guid><description>&lt;p&gt;I&amp;rsquo;ve been doing some interesting work with the team at MFlow writing HTTP clients that consume financial data, and it&amp;rsquo;s been eye-opening to see how different API platforms choose to protect their resources. Best practices for &lt;em&gt;client-side&lt;/em&gt; rate limiting seem to be scarce when compared to server-side, so here are my thoughts on the subject and some code samples.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; — wrap &lt;code&gt;*http.Client&lt;/code&gt; and call &lt;code&gt;limiter.Wait(ctx)&lt;/code&gt; before every request, where &lt;code&gt;limiter&lt;/code&gt; is a &lt;code&gt;*rate.Limiter&lt;/code&gt; from &lt;a href="https://pkg.go.dev/golang.org/x/time/rate" target="_blank" rel="noopener noreffer"&gt;&lt;code&gt;golang.org/x/time/rate&lt;/code&gt;&lt;/a&gt;
. The token bucket honours bursts, blocks cleanly when you&amp;rsquo;re out of tokens, and respects context cancellation.&lt;/p&gt;</description></item></channel></rss>