<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>API Design on Prateek Sharma</title>
		<link>https://prateeksharma.me/tags/api-design/</link>
		<description>Recent content in API Design on Prateek Sharma</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Fri, 28 Aug 2026 00:00:00 +0000</lastBuildDate>
		
			<atom:link href="https://prateeksharma.me/tags/api-design/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Give callers two error types, one extending the other</title>
				<link>https://prateeksharma.me/opinions/two-exceptions-not-one/</link>
				<pubDate>Fri, 28 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/opinions/two-exceptions-not-one/</guid>
				<description>&lt;p&gt;In the &lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-java/&#34;&gt;WazirX Java connector&lt;/a&gt;&#xA; I split errors&#xA;into two:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;WazirxClientException&lt;/code&gt; — the caller made a mistake the caller can fix: a bad&#xA;&lt;code&gt;side&lt;/code&gt; value, a missing required field. Thrown before a request is even sent.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;WazirxApiException&lt;/code&gt; — something went wrong once the request left the process:&#xA;a network failure, a non-2xx response.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;code&gt;WazirxClientException extends WazirxApiException&lt;/code&gt;. That one line is the whole&#xA;design. A caller who only cares &amp;ldquo;did this work?&amp;rdquo; catches the parent. A caller who&#xA;wants to retry network failures but fail fast on their own bad input catches both&#xA;separately. Nobody is forced into a giant &lt;code&gt;catch (Exception e)&lt;/code&gt; that swallows&#xA;bugs, and nobody has to &lt;code&gt;try/catch&lt;/code&gt; five specific types at every call site.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Generic returns can be the right call for a library you maintain alone</title>
				<link>https://prateeksharma.me/opinions/generic-returns-for-a-solo-maintained-library/</link>
				<pubDate>Wed, 26 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/opinions/generic-returns-for-a-solo-maintained-library/</guid>
				<description>&lt;p&gt;The standard advice for a client library is: give callers typed responses.&#xA;&lt;code&gt;client.Ticker(...) (*Ticker, error)&lt;/code&gt;, not &lt;code&gt;(any, error)&lt;/code&gt;. I went the other way&#xA;in my &lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-go/&#34;&gt;WazirX Go connector&lt;/a&gt;&#xA; and I still think it&#xA;was right &lt;em&gt;for that library&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The upstream API&amp;rsquo;s response shapes move around — objects that become arrays,&#xA;fields that appear and vanish across endpoints. With ~25 endpoints and one&#xA;maintainer (me, in spare hours), typed structs would mean 25 things to keep in&#xA;sync with an API I don&amp;rsquo;t control and can&amp;rsquo;t see changes to until they ship. The&#xA;generic return pushed that cost to the call site, where the caller already knows&#xA;which two fields they want and can assert for them.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Endpoint maps over hand-rolled methods</title>
				<link>https://prateeksharma.me/blog/endpoint-maps-over-hand-rolled-methods/</link>
				<pubDate>Tue, 25 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/blog/endpoint-maps-over-hand-rolled-methods/</guid>
				<description>&lt;p&gt;I&amp;rsquo;ve now written two client libraries for the same exchange API — one in&#xA;&lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-go/&#34;&gt;Go&lt;/a&gt;&#xA;, one in&#xA;&lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-java/&#34;&gt;Java&lt;/a&gt;&#xA; — and the thing I&amp;rsquo;d keep from both is&#xA;the same: don&amp;rsquo;t write a method per endpoint. Describe the endpoints as data and&#xA;dispatch through one function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-shape-of-the-problem&#34;&gt;The shape of the problem&lt;/h2&gt;&#xA;&lt;p&gt;The API has roughly two dozen endpoints. They differ in four ways:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;HTTP verb (&lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;path&lt;/li&gt;&#xA;&lt;li&gt;whether the request must be signed&lt;/li&gt;&#xA;&lt;li&gt;the response body&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Everything else — building query params, adding a signature, choosing the verb&#xA;handler, parsing the response — is identical. Writing a hand-rolled method per&#xA;endpoint means writing that identical body 25 times, and then maintaining 25&#xA;copies of it when the signing scheme or the base URL handling changes.&lt;/p&gt;</description>
			</item>
			<item>
				<title>WazirX Go Connector</title>
				<link>https://prateeksharma.me/projects/wazirx-connector-go/</link>
				<pubDate>Sun, 23 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/projects/wazirx-connector-go/</guid>
				<description>&lt;p&gt;&lt;a href=&#34;https://wazirx.com&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;WazirX&lt;/a&gt;&#xA; is one of India&amp;rsquo;s largest crypto exchanges, and&#xA;while its REST API is well documented, it doesn&amp;rsquo;t ship an official Go client. I&#xA;wanted to poke at their API for a side project and didn&amp;rsquo;t want to hand-roll&#xA;request signing and endpoint plumbing every time, so I built&#xA;&lt;a href=&#34;https://github.com/pratts/wazirx-connector-go&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;wazirx-connector-go&lt;/a&gt;&#xA; and&#xA;open-sourced it once it was in decent shape.&lt;/p&gt;&#xA;&lt;h2 id=&#34;avoiding-25-near-identical-methods&#34;&gt;Avoiding ~25 near-identical methods&lt;/h2&gt;&#xA;&lt;p&gt;The exchange exposes close to two dozen endpoints — tickers, order book depth,&#xA;order placement, withdrawals, sub-account transfers, and so on. Writing a&#xA;hand-rolled method for each one would have meant the same boilerplate repeated&#xA;two dozen times: build params, sign if needed, pick GET/POST/DELETE, hit the URL,&#xA;parse the response.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
