<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: JustC</title>
    <description>The latest articles on DEV Community by JustC (@justcatdev).</description>
    <link>https://dev.to/justcatdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2848758%2Fd052f04c-d5bc-411c-a51b-088c79f9bdee.png</url>
      <title>DEV Community: JustC</title>
      <link>https://dev.to/justcatdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/justcatdev"/>
    <language>en</language>
    <item>
      <title>The slippery slope</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Mon, 16 Feb 2026 21:00:30 +0000</pubDate>
      <link>https://dev.to/justcatdev/the-slippery-slope-g1h</link>
      <guid>https://dev.to/justcatdev/the-slippery-slope-g1h</guid>
      <description>&lt;p&gt;Recently came across a post on LinkedIn related to query params in URI. In very simple words, the problem was related to &lt;strong&gt;&lt;em&gt;GETting&lt;/em&gt;&lt;/strong&gt; alternate representation of a resource.&lt;br&gt;
Let's take an example of simple api call&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;Request:
GET /users/1

Response:
HTTP/1.1 200 Requested user details
Content-Type:  application/json

{"username": "Name", "displayName": "Display Name"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If requester is only interested in &lt;strong&gt;&lt;em&gt;displayName&lt;/em&gt;&lt;/strong&gt;, the request can be made as.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;Request:
GET /user/1?fields=displayName

Response:
HTTP/1.1 200 Requested user details
Content-Type: application/json

{"displayName": "Display Name"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks reasonable. It works.&lt;br&gt;
But what exactly are we asking the URI to represent?&lt;br&gt;
The request simply means, we are looking for a way to apply &lt;strong&gt;&lt;em&gt;projection&lt;/em&gt;&lt;/strong&gt; to retrieve only the &lt;strong&gt;&lt;em&gt;displayName&lt;/em&gt;&lt;/strong&gt; and it seems legit. Is it though?&lt;/p&gt;

&lt;p&gt;Let's look at &lt;strong&gt;&lt;em&gt;RFC 3986&lt;/em&gt;&lt;/strong&gt;, especially the part where it talks about syntax of URI or Uniform Resource Identifier.&lt;/p&gt;

&lt;p&gt;A URI is composed of five main components, following this hierarchical pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;scheme ":" hier-part [ "?" query ] [ "#" fragment ] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Scheme&lt;/em&gt;&lt;/strong&gt;: The protocol used (e.g., http, ftp, mailto). It is case-insensitive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Authority&lt;/em&gt;&lt;/strong&gt;: Usually contains the host (IP or registered name) and optional port and userinfo (e.g., //&lt;a href="http://www.example.com:80" rel="noopener noreferrer"&gt;www.example.com:80&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Path&lt;/em&gt;&lt;/strong&gt;: A sequence of segments that identifies a resource within the scope of the scheme and authority.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Query&lt;/em&gt;&lt;/strong&gt;: Non-hierarchical data, often key=value pairs, preceded by ?.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Fragment&lt;/em&gt;&lt;/strong&gt;: Identifies a secondary resource within the primary one (e.g., a page anchor), preceded by #. It is processed by the user agent, not the server. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still seems legit until you start see more such patterns&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/1?fields=displayName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How about&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/?sort=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/?filter=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's rewrite the the first example little differently&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users?id=1&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;fields=displayName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the oddity starts to become visible. &lt;strong&gt;&lt;em&gt;id&lt;/em&gt;&lt;/strong&gt; is, obviously, the search param, but &lt;strong&gt;&lt;em&gt;fields&lt;/em&gt;&lt;/strong&gt; is a &lt;strong&gt;projection&lt;/strong&gt;. Query params sort, fields, filter, etc. are used as mini-instructions on top of limited set of HTTP verbs. People start using it, and it literally starts shaping up as a standard. &lt;/p&gt;

&lt;h2&gt;
  
  
  Anything wrong?
&lt;/h2&gt;

&lt;p&gt;Not really. RFC 3986 is clear that stuff following "?" is just bunch of key-value pairs. In fact the entire URI is &lt;strong&gt;&lt;em&gt;opaque&lt;/em&gt;&lt;/strong&gt;, if you decipher the RFC. So much so, you would hear &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a good REST API treats the query string as a structured DSL (Domain Specific Language) for the resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's the beauty of ReST. Being just a guideline, you see such pragmatic shortcuts that work in real life and often more useful.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;RFC allows it.&lt;br&gt;
The concern is not correctness, it's architectural drift.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Purist view
&lt;/h2&gt;

&lt;p&gt;I must present a different take on the topic, otherwise this post is meaningless. The DSL keywords sort, fields, filter, etc. start crowding the limited set of verbs, and I, as a developer of API, am now forced to maintain documentation around them. Also is a fact that these mini-instructions become part of set of reserved words. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URI -&amp;gt; DSL&lt;/li&gt;
&lt;li&gt;DSL -&amp;gt; Implicit contract&lt;/li&gt;
&lt;li&gt;Contract -&amp;gt; Hidden protocol&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If projection is a representation concern rather than resource selection, then HTTP already provides a mechanism: content negotiation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/1
Accept: application/json; fields=displayName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might have seen this in a different form as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/1
Accept: application/json; q=0.9;charset=UTF-8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The string following the media type can be used to convey additional hints about the media-type interpretation. The key-value pairs that trail the media-type are conveniently called as &lt;strong&gt;&lt;em&gt;media-type parameters&lt;/em&gt;&lt;/strong&gt;. These are open-ended too, you can have as many as you prefer, just have server implementation to process them.&lt;/p&gt;

&lt;p&gt;You want more standard driven approach, follow &lt;a href="https://datatracker.ietf.org/doc/html/rfc6906#section-3.1" rel="noopener noreferrer"&gt;RFC 6906&lt;/a&gt;. It adds more structure to asking for representation &lt;strong&gt;&lt;em&gt;variations&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/1
Accept: application/json; profile="http://www.example.com/profiles/user-summary"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can come up with your own custom media-type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users/1
Accept: application/vnd.user.displayname+json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Then why is it not used?
&lt;/h2&gt;

&lt;p&gt;There are few very practical reasons rooted in the way web works.&lt;/p&gt;

&lt;p&gt;Links are essential part of creations responses. It is much easier to convey the newly created url as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;Location: /user/1?fields=displayName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;than bunch of additional instructions to the client on top of regular GET. You would need to enrich the response with more headers.&lt;/p&gt;

&lt;p&gt;Caches are not smart enough to understand these nuances. One has to sprinkle "Vary:" headers to make caches understand what to cache. It is more of hit and miss with different cache implementations.&lt;/p&gt;

&lt;p&gt;Purpose of this post is not advocacy of purist approach. I just want to make a point that "Common practice does not automatically make it architectural practice." The roots should not be forgotten and pragmatic shortcuts must be explicitly registered as shortcuts than standard. Once the real reason for the shortcuts is forgotten, soon a &lt;strong&gt;&lt;em&gt;slippery slope&lt;/em&gt;&lt;/strong&gt; makes it faster to lose the grip of standards.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Architecture erodes not through wrong decisions, but through forgotten reasons.”&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>api</category>
      <category>architecture</category>
      <category>backend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Seed Corn</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Fri, 02 Jan 2026 19:56:12 +0000</pubDate>
      <link>https://dev.to/justcatdev/the-seed-corn-4pn4</link>
      <guid>https://dev.to/justcatdev/the-seed-corn-4pn4</guid>
      <description>&lt;h2&gt;
  
  
  Episode II
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/justcatdev/the-luxury-layer-205b/"&gt;The first episode&lt;/a&gt; discussed &lt;em&gt;&lt;strong&gt;the thinkers&lt;/strong&gt;&lt;/em&gt;; this episode focuses on &lt;em&gt;&lt;strong&gt;the doers&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is not an argument against automation or AI.&lt;br&gt;
It is an argument against mistaking acceleration for succession.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The doers&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Execute -&amp;gt; Build -&amp;gt; Operate&lt;/li&gt;
&lt;li&gt;As they work, they accumulate the &lt;strong&gt;&lt;em&gt;tacit/tribal knowledge&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Earn &lt;strong&gt;&lt;em&gt;battle scars&lt;/em&gt;&lt;/strong&gt;, and more importantly, the &lt;strong&gt;&lt;em&gt;judgment&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Over time, some transition to become "The Thinkers"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The doers are thinkers in &lt;strong&gt;&lt;em&gt;incubation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You don’t grow thinkers by hiring them.&lt;br&gt;
You grow them by letting doers survive long enough to reflect.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Automation attacks &lt;strong&gt;&lt;em&gt;the doer layer&lt;/em&gt;&lt;/strong&gt; first.&lt;/p&gt;

&lt;p&gt;Not because doers lack value, but because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;their work is observable&lt;/li&gt;
&lt;li&gt;repeatable&lt;/li&gt;
&lt;li&gt;specifiable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The immediate gain looks rational:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cheaper&lt;/li&gt;
&lt;li&gt;faster&lt;/li&gt;
&lt;li&gt;scalable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But the unseen loss is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are not just removing labour...&lt;br&gt;
You are removing the future thinkers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is &lt;strong&gt;&lt;em&gt;the seed corn&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The missing question
&lt;/h3&gt;

&lt;p&gt;AI is absolutely needed&lt;br&gt;
It is powerful, efficient.&lt;/p&gt;

&lt;p&gt;The missing point is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If AI is to automate the work that once trained our future thinkers, then we must deliberately invent new paths for judgment to form.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>leadership</category>
      <category>career</category>
      <category>discuss</category>
      <category>automation</category>
    </item>
    <item>
      <title>The Luxury Layer</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Thu, 18 Dec 2025 19:45:13 +0000</pubDate>
      <link>https://dev.to/justcatdev/the-luxury-layer-205b</link>
      <guid>https://dev.to/justcatdev/the-luxury-layer-205b</guid>
      <description>&lt;h2&gt;
  
  
  Episode I
&lt;/h2&gt;

&lt;p&gt;I would like to begin with a single-question survey:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Do you need &lt;em&gt;thinkers&lt;/em&gt; or &lt;em&gt;doers&lt;/em&gt;? &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;The likely answer is &lt;em&gt;doers&lt;/em&gt;. &lt;br&gt;
After all work won't get done just by thinking, will it?&lt;/p&gt;

&lt;p&gt;So, are thinkers really needed?&lt;/p&gt;

&lt;p&gt;It is a &lt;em&gt;luxury&lt;/em&gt; to afford employing group of thinkers.&lt;/p&gt;

&lt;p&gt;Let me clarify what I am referring to as &lt;em&gt;Thinkers&lt;/em&gt;. You may have noticed or about to notice that in this age of AI, sooner or later, the roles or titles like &lt;em&gt;Principal Engineers&lt;/em&gt;, &lt;em&gt;Specialists&lt;/em&gt;, &lt;em&gt;Architects&lt;/em&gt;, and such would be or already are reframed to be&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Too narrow&lt;/li&gt;
&lt;li&gt;Non-executional&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Redundant&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"Redundant" because, sooner or later, work gets detailed enough to match thinker's visions.&lt;/p&gt;

&lt;p&gt;These visions are what:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reduce future failures&lt;/li&gt;
&lt;li&gt;prevent scaling disasters&lt;/li&gt;
&lt;li&gt;encode &lt;strong&gt;&lt;em&gt;tribal knowledge&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of the above shows up cleanly in any quarterly &lt;em&gt;EBITDA&lt;/em&gt; making it difficult to justify these roles. These roles would remain redundant until things actually start breaking.&lt;/p&gt;

&lt;p&gt;The promotional messages to curtail thinkers is often:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We don't need thinkers anymore, we need doers + tools&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No doubt AI is good, it is very useful. AI replaces&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;repetitive synthesis&lt;/li&gt;
&lt;li&gt;boilerplate decisioning&lt;/li&gt;
&lt;li&gt;&lt;em&gt;low-context abstraction&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But low-context abstractions is not sufficient to grasp the unsaid, the tribal knowledge. AI in its current form needs significant help to &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;have a &lt;em&gt;systems intuition&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;failure anticipation&lt;/li&gt;
&lt;li&gt;boundary judgements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am not saying AI cant do it.&lt;br&gt;
I am saying &lt;strong&gt;AI + a thinker&lt;/strong&gt; would pair nicely.&lt;/p&gt;

&lt;p&gt;The thinker roles have&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;long-term &lt;em&gt;systems thinking&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;tacit, experience-earned knowledge&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Replacing judgement with tools wont make systems safer. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We are entering an era where &lt;em&gt;&lt;strong&gt;bad architecture&lt;/strong&gt; will be shipped faster&lt;/em&gt; and paid for later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Soon it is going to be frustrating for thinkers to justify the &lt;em&gt;the luxury layer&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Earlier in the career justifications are part of growth and after years of grinding the justification would feel like an erasure as the value of these roles is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cumulative&lt;/li&gt;
&lt;li&gt;contextual&lt;/li&gt;
&lt;li&gt;earned through scars&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI is great and people have understood its worth in&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;automation (tools)&lt;/li&gt;
&lt;li&gt;Acceleration (productivity)&lt;/li&gt;
&lt;li&gt;Judgement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First two are easy to ratify and certainly real. Judgement, on the other hand, is not. Judgement needs high context systems thinking. &lt;/p&gt;

&lt;p&gt;Overtime AI would catch-up giving rise to newer problems expanding the context to even wider horizons.&lt;/p&gt;

&lt;p&gt;You would notice now that value of such roles is&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in the negative space (things that don't break)&lt;/li&gt;
&lt;li&gt;their impact is delayed or not even felt&lt;/li&gt;
&lt;li&gt;their work is preventive not demonstrative &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Such work often goes unnoticed and it can feel dispensable.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>architecture</category>
      <category>career</category>
      <category>ai</category>
    </item>
    <item>
      <title>ReST: Not a Silver Bullet</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Sat, 22 Mar 2025 04:37:47 +0000</pubDate>
      <link>https://dev.to/justcatdev/rest-not-a-silver-bullet-257i</link>
      <guid>https://dev.to/justcatdev/rest-not-a-silver-bullet-257i</guid>
      <description>&lt;p&gt;In previous episodes and through this series, I’ve challenged well-established notions about ReST. Now that you're drawn to ReST, hearing that it's not a silver bullet might surprise you. The intent of this series was never to pitch ReST but to inspire critical thinking. ReST is wonderful. ReST is simple. ReST is flexible. Yet, it remains one of the most misunderstood and misused styles. Using ReST to drive home a point just made sense.&lt;/p&gt;

&lt;p&gt;Software design is a bit different from its traditional counterparts. Use cases are key to any software design, and I’m going to use a few of them to explain why ReST is not a silver bullet.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Use Case
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;So, what is a use case really?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A use case is a specific situation or scenario in which a system, product, or service is used to achieve a goal. It describes an interaction between a user and the system, focusing on how the system fulfills a need or solves a problem.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What Are the Key Elements of a Use Case?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;User&lt;/strong&gt;&lt;/em&gt;: The individual or entity interacting with the system.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Goal&lt;/strong&gt;&lt;/em&gt;: The intended outcome or purpose of the system.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;System&lt;/strong&gt;&lt;/em&gt;: The tool enabling the execution of the use case.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;/em&gt;: The environment, circumstances, or conditions in which the use case occurs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You’ll notice that context matters significantly and drives most of the design choices. Let’s explore a few examples to illustrate why ReST is not a silver bullet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Communication
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Why?&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
ReST is strictly a request-reply design. Nothing happens unless a request is made. A ReST service cannot push notifications to its audience because it wasn’t designed for such applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Alternatives&lt;/strong&gt;&lt;/em&gt;: You can use WebSockets or Server-Sent Events (SSE) to handle real-time communication.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Latency and Bandwidth-Sensitive Systems
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Why?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;ReST is stateless, making real-time communication verbose, as each request must be independent and therefore bulky. This isn’t bandwidth-friendly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Alternatives&lt;/strong&gt;&lt;/em&gt;: Use binary protocols like Protocol Buffers (protobuf) that are optimized for such scenarios. These protocols eliminate the need for headers, status codes, etc., making communication more efficient.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Inherited Non-ReST System
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Why?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, you inherit a non-ReST system and are unable to change it. This doesn’t mean you can’t improve it, but the scope might be limited to smaller features rather than a full overhaul.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Alternatives&lt;/strong&gt;&lt;/em&gt;: Unfortunately, there might not be a viable alternative when you’re constrained by the system you’ve inherited. Overhauling may not be an option, so ReST might also be out of reach. However, this isn’t inherently a bad thing—it’s simply a matter of doing the job that needs to be done.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There are plenty of situations where ReST simply isn’t the right choice. That doesn’t mean everything we’ve discussed in this series is inapplicable. The key is to understand your use cases, determine what fits well, and then craft the interactions accordingly. The idea of viewing interactions as human-like conversations isn’t limited to request-reply styles like ReST. A similar thought process can be equally useful in event-driven architectures too.&lt;/p&gt;

</description>
      <category>restapi</category>
      <category>architecture</category>
      <category>programming</category>
      <category>microservices</category>
    </item>
    <item>
      <title>ReST: It is more than just a CRUD over HTTP</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Fri, 21 Mar 2025 13:11:55 +0000</pubDate>
      <link>https://dev.to/justcatdev/rest-it-is-more-than-just-a-crud-over-http-31gi</link>
      <guid>https://dev.to/justcatdev/rest-it-is-more-than-just-a-crud-over-http-31gi</guid>
      <description>&lt;p&gt;While CRUD provides a foundational understanding of HTTP verbs, it oversimplifies ReST API design. Many argue that ReST is just CRUD over HTTP, with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt; corresponds to creation,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt; to retrieval,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT&lt;/strong&gt; to updating, and&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE&lt;/strong&gt; to deletion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While this analogy seems reasonable and works for most people, it is worth considering if there is more to it. Shoehorning a to CRUD overlooks the depth of designing systems that truly serve user intent.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/justcatdev/rest-the-need-to-talk-j1j"&gt;&lt;em&gt;first episode&lt;/em&gt;&lt;/a&gt; of this ReST series, I introduced a key idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ReST API design is like scripting a dialogue between two people&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 1: Agree on the "Language" of the Conversation
&lt;/h2&gt;

&lt;p&gt;The first step in designing a ReST API is deciding on the "language" of the conversation, essentially, the format used to exchange information. Think of it as agreeing beforehand on whether you'll "speak" in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plain text,&lt;/li&gt;
&lt;li&gt;JSON,&lt;/li&gt;
&lt;li&gt;XML, or&lt;/li&gt;
&lt;li&gt;a brand-new format unique to your API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures that both parties, the user and the system, can understand each other clearly from the outset.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Understand the User’s Intentions
&lt;/h2&gt;

&lt;p&gt;Next, focus on understanding the requirements, which are essentially the user's intentions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;What are they trying to achieve?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;What is the simplest, most natural way for them to express their request?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Craft a Dialogue
&lt;/h2&gt;

&lt;p&gt;Once you’ve understood the intention:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Formulate a &lt;strong&gt;request&lt;/strong&gt; on the user’s behalf.&lt;/li&gt;
&lt;li&gt;Craft a &lt;strong&gt;response&lt;/strong&gt; that mirrors how a person would naturally reply:

&lt;ul&gt;
&lt;li&gt;Is the response clear and precise?&lt;/li&gt;
&lt;li&gt;Does it provide all the necessary information?&lt;/li&gt;
&lt;li&gt;Does it gracefully handle errors or misunderstandings?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By treating API design as scripting a meaningful dialogue, you can create systems that feel intuitive, purposeful, and human-centric.&lt;/p&gt;

&lt;p&gt;Now that we've established the importance of crafting meaningful dialogues, let’s take the example of order cancellation.&lt;/p&gt;

&lt;h3&gt;
  
  
  CRUD Way
&lt;/h3&gt;

&lt;p&gt;At first glance, the user’s intention seems straightforward,  they want to cancel the order. A lazy approach might map this action directly to a &lt;code&gt;DELETE&lt;/code&gt; request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;DELETE /orders/1234
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While technically valid, this design overlooks a critical aspect: understanding the &lt;em&gt;&lt;strong&gt;“why.”&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As a business owner, knowing why an order is canceled is priceless. It opens opportunities to improve services, address customer concerns, and potentially recover the relationship. A simple DELETE erases the order but loses the chance to ask the customer questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Was there an issue with the product?&lt;/li&gt;
&lt;li&gt;Was the delivery timeline too long?&lt;/li&gt;
&lt;li&gt;Did the price feel too high?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By framing the cancellation process more thoughtfully, perhaps through a POST to a “CancelledOrders” endpoint with a reason code or message you capture the humane aspect of the dialogue. This way, the API design doesn’t just serve the technical need but also aligns with broader business goals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intent-Based Way
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;POST /CancelledOrders  
Content-Type: application/json

{
  "orderId": 1234,
  "reason": "price too high"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A word about nouns
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;CancelledOrders&lt;/strong&gt;&lt;/em&gt; is a noun and at times you might need some time to come up with a meaningful noun. One may come up with a rather odd noun, &lt;em&gt;&lt;strong&gt;OrderCanceller&lt;/strong&gt;&lt;/em&gt;, and there is nothing wrong, ReST does not stop one from doing that. By the way this is a classic ReST design dilemma.&lt;/p&gt;

&lt;p&gt;Let’s look at these two nouns systematically, balancing opinions and rationale.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: Resource Oriented (ex. CancelledOrders)
&lt;/h3&gt;

&lt;p&gt;This approach treats cancellations as a distinct resource with its own lifecycle, attributes, and state, while keeping the original Order resource untouched.&lt;/p&gt;

&lt;h4&gt;
  
  
  Advantages:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ReSTful Purity:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Emphasizes nouns/resources over actions, aligning with ReST's guideline of avoiding verbs in URIs.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;CancelledOrder&lt;/code&gt; is conceptually distinct from an active &lt;code&gt;Order&lt;/code&gt;, which makes this separation intuitive for consumers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;State Representation:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Captures the cancellation reason and metadata (timestamp, actor, etc.) naturally as attributes of the CancelledOrder resource.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extensibility:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Provides flexibility to evolve the cancellation model independently of the Order model (e.g., add cancellation-specific rules or workflows).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Disadvantages:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Introduces a new resource to manage, including relationships with the original Order (e.g., CancelledOrder must reference the Order it pertains to).&lt;/li&gt;
&lt;li&gt;Consumers must now interact with multiple resources to get the full lifecycle of an order.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Perceived Redundancy:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Since cancellation is inherently an action on an order, creating a new resource for it can feel contrived.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Option 2: Action oriented (ex. OrderCanceller)
&lt;/h3&gt;

&lt;p&gt;OrderCanceller does not sound English. Well, it sounds made up, most nouns are. This approach represents cancellations as an action performed on an Order, captured via a dedicated actor resource (OrderCanceller) or a simple status update to the Order resource.&lt;/p&gt;

&lt;h4&gt;
  
  
  Advantages:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Maintains the focus on the Order resource, which remains central to all operations (placing, updating, canceling).&lt;/li&gt;
&lt;li&gt;No additional resource is introduced; cancellation updates the status field of an existing Order object.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clarity of Action:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;For consumers, "cancelling an order" as an action maps naturally to POST /orders/{id}/cancel or PATCH /orders/{id}.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Object Modeling:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Updates occur in-place without duplicating data or introducing relationships, making implementation simpler.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Disadvantages:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Action Verb Leakage:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Despite wrapping the action in a noun (OrderCanceller), this approach may still feel action-oriented, which some might see as less ReSTful.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loss of Explicit History:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;If cancellations are just status changes, capturing detailed cancellation metadata (reason, actor, timestamp) requires extra fields or audit logs, muddying the core Order resource.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Balancing Opinion and Rationality
&lt;/h3&gt;

&lt;p&gt;The choice hinges on whether you prioritize conceptual clarity (resource orientation) or operational simplicity (action orientation):&lt;/p&gt;

&lt;h4&gt;
  
  
  When to Choose Resource-Oriented (&lt;code&gt;CancelledOrders&lt;/code&gt;):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Cancellation has its own business significance or lifecycle beyond being an "action" (e.g., analyzing cancellations, auditing reasons).&lt;/li&gt;
&lt;li&gt;You expect cancellations to have complex attributes (e.g., reasons, timestamps, or even nested workflows like approvals).&lt;/li&gt;
&lt;li&gt;Aligning closely with ReSTful principles is critical for consistency across your API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  When to Choose Action-Oriented (&lt;code&gt;OrderCanceller&lt;/code&gt;):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Simplicity and operational focus are higher priorities than conceptual purity.&lt;/li&gt;
&lt;li&gt;Cancellation is a transient state rather than a key part of your domain model.&lt;/li&gt;
&lt;li&gt;Your system and consumers are more accustomed to action-based APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Concluding thoughts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If the reason for cancellation or its auditability is significant to your business, go with CancelledOrders. It better encapsulates the separation of concerns, making cancellation its own first-class entity. This aligns well with resource-centric ReST design.&lt;/li&gt;
&lt;li&gt;If simplicity and immediacy are paramount, and cancellation is a minor detail, use the action-oriented approach with an Order status update.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Note:
&lt;/h2&gt;

&lt;p&gt;Nouns don’t need to sound English, but they should align with how your domain experts and API consumers naturally think. If &lt;code&gt;OrderCanceller&lt;/code&gt; feels contrived, it might signal that &lt;code&gt;CancelledOrders&lt;/code&gt; is the more domain-appropriate model.&lt;/p&gt;

</description>
      <category>restapi</category>
      <category>architecture</category>
      <category>programming</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Range Headers: Pagination the HTTP way</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Sun, 16 Mar 2025 17:49:18 +0000</pubDate>
      <link>https://dev.to/justcatdev/range-headers-pagination-the-http-way-31mf</link>
      <guid>https://dev.to/justcatdev/range-headers-pagination-the-http-way-31mf</guid>
      <description>&lt;p&gt;Originally published on &lt;a href="https://hackernoon.com/range-headers-what-are-they-and-how-to-use-them" rel="noopener noreferrer"&gt;HackerNoon&lt;/a&gt;, this post is now available on dev.to.&lt;/p&gt;

&lt;p&gt;This is the second episode of the ReST series! While the first episode centered around semantics, this installment delves into the ways in which request and response headers can enhance interactions, making them more meaningful and comprehensive. For the sake of a focused narrative, we'll concentrate on a common issue: the pagination problem.&lt;/p&gt;

&lt;p&gt;In this episode, our primary focus will be on understanding how HTTP Range headers can be employed to address the challenges associated with pagination. By narrowing our scope, we aim to provide a clearer and more in-depth exploration of this specific aspect of RESTful API design.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Pagination?
&lt;/h2&gt;

&lt;p&gt;Simplistically, pagination means splitting large datasets into comprehensible smaller sets and providing means to navigate across these smaller sets. An example would be, say, in some web application, a search for users yields thousands of results.&lt;/p&gt;

&lt;p&gt;It would be impractical to overwhelm the poor soul with all results at once. First of all, the convenience of searching for large datasets is no longer a convenience, rather it is a nuisance.&lt;/p&gt;

&lt;p&gt;Now, this post may also come as a rant as there are multiple ways to implement it, and the way I feel it should be done is not possible with current specifications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pagination Using Query Params
&lt;/h3&gt;

&lt;p&gt;OData specification has support for pagination, and it makes use of query parameters to implement pagination. A typical OData interaction can look as below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Request:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users?$skip=0&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;$top=10&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;$inlinecount=allpages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;200 Okay
X-Some-Side-Channel: count=200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, that’s an example of repurposing. Here, the query string is repurposed for pagination. It sounds a bit weird from the get-go. The query string, the name itself, states its purpose “for querying” and is repurposed.&lt;/p&gt;

&lt;p&gt;There is a header prefixed X-, and such headers are called custom headers. User-agent needs to understand it, or there is a need for customization in the form of coding at the client end.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can We Do Better?
&lt;/h3&gt;

&lt;p&gt;RFC2616 had a section on content ranges as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;14.35.2 Range Retrieval Requests

HTTP retrieval requests using conditional or unconditional GET
methods MAY request one or more sub-ranges of the entity, instead
of the entire entity, using the Range request header, which applies
to the entity returned as the result of the request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Does that sound similar to pagination?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s try to model the earlier OData request using Range Retrieval Request. Ranges are resource-specific meaning &lt;code&gt;/users&lt;/code&gt; may be a collection of more than one, user data. A single user is a unit in the collection.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Let’s Ask: What Is a Unit for Users’ Resource?&lt;/em&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Request:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;OPTION /users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;200 Okay
Accept-Ranges: users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The web application is telling us that &lt;em&gt;&lt;strong&gt;users&lt;/strong&gt;&lt;/em&gt; is a unit to specify the range of users. Now, since we got to know that users is the unit, let’s ask for the first 10 users.&lt;/p&gt;

&lt;h4&gt;
  
  
  Request:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users
Range: users=0-9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;206 Partial Content
Accept-Ranges: users
Content-Range: users 0-9/200


[ 0, …, 9 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;em&gt;How does this dialogue work?&lt;/em&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What does Request say?
&lt;/h4&gt;

&lt;p&gt;In the request, the user-agent has added a Range header mentioning a specific unit discovered from earlier OPTIONS dialogue and a range in numeric form. Natural, isn’t it?&lt;/p&gt;

&lt;h4&gt;
  
  
  What does Response say?
&lt;/h4&gt;

&lt;p&gt;The web application responds with &lt;em&gt;&lt;strong&gt;206&lt;/strong&gt;&lt;/em&gt; clearly stating that the response is partial. Content-Range provides details about the data in the response. In the example, 0-9/200 indicates the first 10 users’ data is being returned out of 200, the number of users satisfying the search query.&lt;/p&gt;

&lt;p&gt;It also reiterates the unit being users as &lt;em&gt;&lt;strong&gt;Accept-Ranges&lt;/strong&gt;&lt;/em&gt; header. Since Accept-Ranges is reiterated, the &lt;em&gt;&lt;strong&gt;OPTIONS&lt;/strong&gt;&lt;/em&gt; call can be avoided altogether as the web application can simply default to sane defaults for the range parameters if the request did not send the Range header.&lt;/p&gt;

&lt;p&gt;At times, it might be very intensive to compute the total number of records in the returned collection. In such cases, one can simply respond with * as count. So, the response looks as below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;206 Partial Content
Accept-Ranges: users
Content-Range: users 0-9/*


[ 0, …, 9 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;You can ask for multiple ranges too.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Request:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users
Range: users=0-9,35-50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;206 Partial Content
Accept-Ranges: users
Content-Type: multipart/mixed; boundary=PART


--PART
Content-Range: users 0-9
[ 0, …, 9 ]


--PART
Content-Range: 35-50
[ 35, …, 50]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;em&gt;What if the data requested is beyond the range?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;The web application can simply state that the data is not available.&lt;/p&gt;

&lt;h4&gt;
  
  
  Request:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /users
Range: users=0-9,35-50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;416 Requested range is not satisfiable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  But (The Rant Part)
&lt;/h2&gt;

&lt;p&gt;All this discussion about Range headers might feel like a lot of talk. The potential usefulness of Range headers is, for now, mostly theoretical. While originally mentioned in RFC 2616, the specification explicitly mentions only bytes as the unit for specifying a range. It doesn't necessarily rule out the possibility of using other units, but it also doesn't affirmatively state that it is allowed.&lt;/p&gt;

&lt;p&gt;Even in the latest specifications on HTTP, namely RFC7231 and RFC7233, the stance remains unchanged. In reality, the sad truth is that as of now, there are no HTTP servers with native support for custom range units. It is like having a tool in the toolbox that looks promising on paper but turns out to be rarely used in practice.&lt;/p&gt;

&lt;p&gt;Whether this will change in the future or if the theoretical potential of Range headers will forever remain just that - theoretical - only time will tell.&lt;/p&gt;

&lt;p&gt;Further reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.ietf.org/rfc/rfc2616.txt" rel="noopener noreferrer"&gt;RFC2616&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.ietf.org/rfc/rfc7231.txt" rel="noopener noreferrer"&gt;RFC7231&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.ietf.org/rfc/rfc7233.txt" rel="noopener noreferrer"&gt;RFC7233&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>restapi</category>
      <category>architecture</category>
      <category>programming</category>
      <category>microservices</category>
    </item>
    <item>
      <title>ReST: The Need to Talk</title>
      <dc:creator>JustC</dc:creator>
      <pubDate>Wed, 05 Mar 2025 16:03:11 +0000</pubDate>
      <link>https://dev.to/justcatdev/rest-the-need-to-talk-j1j</link>
      <guid>https://dev.to/justcatdev/rest-the-need-to-talk-j1j</guid>
      <description>&lt;p&gt;Originally published on &lt;a href="https://hackernoon.com/the-hidden-language-of-computers-and-the-need-to-talk" rel="noopener noreferrer"&gt;HackerNoon&lt;/a&gt;, this post is now available on dev.to.&lt;/p&gt;

&lt;p&gt;In the history of human existence, communication serves as the indispensable thread that weaves connections, understanding, and knowledge. Picture this: in a corner of the comic world, on November 7, 1989, Calvin from Calvin and Hobbes engages in a conversation with his dad over the phone. This seemingly ordinary scene encapsulates a universal truth&lt;/p&gt;

&lt;p&gt;– the need to talk.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftml7xy8xfggok82nj5xf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftml7xy8xfggok82nj5xf.jpeg" alt="Calvin needs help" width="229" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No one is omniscient, see Calvin didn't know 11 + 7. The complexities of life, the myriad of experiences, and the wealth of information that surrounds us demand an incessant quest for understanding. We need to talk to others, at times, to seek answers, perspectives, or simply to share our thoughts. However, this act of communication is not haphazard; it follows a set of unspoken rules, guidelines, and etiquette that transform it into a nuanced art. Communication is, in essence, the bridge that connects minds, allowing ideas to flow, emotions to be shared, and knowledge to be transferred. Yet, mastering this art is no small feat. The intricacies of language, the subtleties of tone, and the all those non-verbal cues all contribute to the richness of human interaction.&lt;/p&gt;

&lt;p&gt;Now, as a coder, I find a parallel allure in translating this intricate communication into the realm of machines talking to machines. In the vast landscape of programming, where precision and clarity are paramount, communication takes a different form.&lt;/p&gt;

&lt;h1&gt;
  
  
  API
&lt;/h1&gt;

&lt;p&gt;An acronym for "Application Programming Interface", though sounding just too technical, is just a term for machines talking to machines. As with any communication, there are varied kinds of it too. SOAP (Simple Object Access Protocol), ReST (Representational State Transfer), RPC (Remote Procedure Calls), etc. just to name a few.&lt;/p&gt;

&lt;p&gt;It is worth noting that communication in the digital realm isn't confined to APIs alone. There's also the intriguing realm of event-driven communication – an asynchronous data exchange that doesn't always wear the API label prominently. Yet, it plays a crucial role in orchestrating seamless interactions between different components, making systems agile and responsive.&lt;/p&gt;

&lt;h1&gt;
  
  
  ReST
&lt;/h1&gt;

&lt;p&gt;I have been dealing with web-apis, flavors of ReST, for almost two decades now. And I say flavors of ReST as ReST is not as stubborn as other such protocols as SOAP simply because it is not a protocol, rather just set of guidelines or architectural style. &lt;/p&gt;

&lt;p&gt;That sets ReST apart from others in very distinct way. ReST makes machine-to-machine communication more humane, simple and natural. Detailing a ReST api is more philosophical than technical, because one always starts with nouns when designing a ReST api.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's in the Name?
&lt;/h2&gt;

&lt;p&gt;Seriously what’s in the name? why are we so obsessed with names and naming things? I had blogged about it a decade ago. It was and still is an opinion of mine that names are nothing more than an abstraction to details. Without names conversation would be too wordy, verbose and still not very clear. We tend to name things and to make things clearer, we add more discriminating names. More the number of nouns, richer the vocabulary. Eskimos have twenty odd names for different kinds of ice. Names are not just limited to things or places, but also cover many actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Actions
&lt;/h2&gt;

&lt;p&gt;But there is a stark difference between names and action. If names and actions are a sets, mathematical sets, you would notice cardinality, number of items in the set, of names increases overtime whereas same is not true for actions. Cut as an action has same name when you are cutting a paper as well as cutting vegetable. Actions, thus, are polymorphic in nature. Same action can be tied to multiple nouns.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP
&lt;/h2&gt;

&lt;p&gt;Enough with philosophy, let’s now focus on technicality. ReST came along with HTTP, and it is hands-in-glove relation. There are few misunderstandings about HTTP, mostly about usage. Most folks look at HTTP as a Transport protocol, they are not to blame though, you can download files with HTTP, so one can easily fall for it. Confusion of HTTP being a Transport protocol stems from the fact that the acronym or abbreviation literally is&lt;/p&gt;

&lt;h2&gt;
  
  
  Hyper-Text Transfer Protocol
&lt;/h2&gt;

&lt;p&gt;When you perform an action using HTTP, it usually involves some sort of Document Shuffle, you are either sending a document to, or receiving one from, a server. The word you really want to focus on is Hyper-Text. Since most of the time the substance of a sentence is usually in the middle, unfortunately many fell for Transfer than Hyper-Text and synonymously used Transport in place of Transfer wherein both are literally different terms.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The fact is HTTP is “Application Protocol”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It works on top of real transport protocols as TCP/IP (Connection Oriented) or UDP or QUIC (Connection Less) in case of HTTP2.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTTP Verbs (Methods)
&lt;/h3&gt;

&lt;p&gt;To shuffle a document HTTP defines very few verbs limited to GET, PUT, DELETE and POST&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;GET&lt;/em&gt;&lt;/strong&gt; is to fetch a document&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;PUT&lt;/em&gt;&lt;/strong&gt; is to place a document&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;DELETE&lt;/em&gt;&lt;/strong&gt; is to remove a document&lt;/li&gt;
&lt;li&gt;And let’s not talk about &lt;strong&gt;&lt;em&gt;POST&lt;/em&gt;&lt;/strong&gt; just yet, let's circle back to it later.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  A Dialogue
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb3htoaxg21u6aozzld3o.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb3htoaxg21u6aozzld3o.jpeg" alt="Typical HTTP dialogue" width="434" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above image depicts a simple dialogue between a user and some web application. Each message in this dialog is some sort of document being shuffled between the parties. Let's not worry about what's shuffled for now. It traces a workflow for the web-application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Media Types
&lt;/h2&gt;

&lt;p&gt;The data which is getting shuttled between server and the user follows certain agreed upon format so both parties can make sense of it. This formatting is dictated as Media Type. Let’s look at few examples.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;text/plain&lt;/li&gt;
&lt;li&gt;text/html&lt;/li&gt;
&lt;li&gt;image/jpeg&lt;/li&gt;
&lt;li&gt;application/xml&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;application/vnd.example+xml&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looks familiar, except may be the last one and I am not referring to the formatting.&lt;/p&gt;

&lt;p&gt;Let’s read the last media type&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;application&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
The media is for consumption by an application not humans&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;vnd&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
This is vendor defined custom media type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;example&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
This is a vendor specified media type name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;+xml&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
This media type is based on already known xml media type&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hyper-Media Types
&lt;/h2&gt;

&lt;p&gt;We have seen media types now what does Hyper mean? User uses some application which talks to server on user’s behalf. The applications employed by users are referred as user-agents. The web browser is an example of user-agent. These user-agents understand and make sense of the media which flows to and from the server.&lt;/p&gt;

&lt;h1&gt;
  
  
  A Nudge
&lt;/h1&gt;

&lt;p&gt;An application at the server must have an agenda as the conversation needs to have a closure. It must end either successfully or unsuccessfully. As with any dialogue user-agent and application on the server take turns to take next step as per the selections by the user-agent, in fact on behalf of the user. Web application is just simply nudging the user to have a closure on ongoing interaction.&lt;/p&gt;

&lt;p&gt;Consider following interaction which depicts one request-reply.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;POST /orders
Host: example.org
Content-type: application/vnd.example+xml
Accept: application/vnd.example+xml

&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 201 Order created
Location: http://example.org/orders/1234
Content-Type:  application/vnd.example+xml

&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;next&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/state-machine”&lt;/span&gt; 
    &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;“payment”&lt;/span&gt;
    &lt;span class="na"&gt;uri=&lt;/span&gt;&lt;span class="s"&gt;“http://example.org/orders/1234/payment”&lt;/span&gt;
  &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;next&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/state-machine”&lt;/span&gt;
    &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;“self”&lt;/span&gt;
    &lt;span class="na"&gt;uri=&lt;/span&gt;&lt;span class="s"&gt;“http://example.org/orders/1234”&lt;/span&gt;
  &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what a &lt;em&gt;browser&lt;/em&gt;, the &lt;em&gt;user-agent&lt;/em&gt;, is sending as a request&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Request Method&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
One of HTTP verbs. In above request it is &lt;strong&gt;POST&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Request URI&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
URI of the resource. In above request it is &lt;strong&gt;/orders&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Request Headers&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Accept&lt;/strong&gt; lets the server know what media type user-agent is interested in&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Content-Type&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Tells the server the data, being sent in the request, is in what format&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Request Body&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
And finally the data which is being sent to the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s breakdown the response received from the server&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;User-agent coordination&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
It talks about the consequence of the request&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP/1.1 &lt;strong&gt;201&lt;/strong&gt; Order created
201 is a status code telling the user-agent that request has been successfully executed and as a consequence a resource is being created. Now resource may sound too technical but in reality what it simply means a new object is created on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Location:&lt;/strong&gt; &lt;a href="http://example.org/orders/1234" rel="noopener noreferrer"&gt;http://example.org/orders/1234&lt;/a&gt;
Location is a response header. It tells user-agent, if interested, it can follow the link in the header and redirect the user-agent to, in this case, to newly created resource.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content-Type:&lt;/strong&gt; application/vnd.example+xml
It simply tells the user-agent that the data which is being sent to it is using application/vnd.example+xml media type.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;The media&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
or the data itself, rest of the bytes sent by the server are simply the actual data.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now since the media type in this case is a custom one, it all depends on user-agent to make sense of it. In the example, user-agent may be smart enough to parse the response data and&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proceed to payments&lt;/li&gt;
&lt;li&gt;Or simply interact with the newly created order resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In either case user-agent may use various HTTP verbs to interact with these resources.&lt;/p&gt;

&lt;p&gt;Server is simply nudging the user, via the user-agent, to finish up the workflow of placing an order.&lt;/p&gt;

&lt;p&gt;Since there are more than one outcomes of the decision taken by user-agent there are few possible interactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Say user wants to cancel the order&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;DELETE /orders/1234
Host: example.org
Accept: application/vnd.example+xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 200 Okay
Content-Type:  application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Cancelled&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Or user wants to proceed with payment&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;POST /orders/1234/payment
Host: example.org
Content-Type:  application/vnd.example+xml
Accept: application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;payment&lt;/span&gt; &lt;span class="na"&gt;orderId=&lt;/span&gt;&lt;span class="s"&gt;“1234”&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
…
&lt;span class="nt"&gt;&amp;lt;/payment&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 201 Receipt generated
Location: http://example.org/orders/1234/receipt
Content-Type:  application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Not Ready&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;next&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/state-machine”&lt;/span&gt;
    &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;“self”&lt;/span&gt;
    &lt;span class="na"&gt;uri=&lt;/span&gt;&lt;span class="s"&gt;“http://example.org/orders/1234”&lt;/span&gt;
  &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In all these interaction user is presented with enough coordination and the media itself to be able to proceed with successfully completing the workflow.&lt;/p&gt;

&lt;p&gt;In case user-agent followed payments and it was successfully processed, as a side-effect receipt would be generated. Coordination data says so by 201 and gives uri to receipt as Location header. Client can now poll the self uri to see if order is ready.&lt;/p&gt;

&lt;p&gt;Polling may sound stupid, but it is extremely effective with use of caches. These caches lessen the burden on the server as more often order is simply not ready immediately as it takes time to work with the order.&lt;/p&gt;

&lt;h1&gt;
  
  
  Curious case of POST
&lt;/h1&gt;

&lt;p&gt;Important point is client has some part of application state locally cached or cached along the chain.&lt;/p&gt;

&lt;p&gt;Now about the POST which was introduced in subtly different way. I am treating it &lt;strong&gt;&lt;em&gt;post&lt;/em&gt;&lt;/strong&gt; other verbs. Creations are mostly associated with POST, when in fact GET followed by a PUT can do the job.&lt;/p&gt;

&lt;p&gt;For example creating a new order can be a series of operations as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;GET&lt;/strong&gt;&lt;/em&gt; last order&lt;/li&gt;
&lt;li&gt;Create new order locally and &lt;em&gt;&lt;strong&gt;Put&lt;/strong&gt;&lt;/em&gt; back the new order&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then why POST?&lt;/p&gt;

&lt;p&gt;Answer is quite obvious, I am merely making it explicit now. One important thing to note is that such applications are, typically, multi-user applications.&lt;/p&gt;

&lt;p&gt;Let's say new order-id is a function of number of orders in the collection + 1. Since it is multi-user application there can be more than one users simultaneously wanting to create new order. All these users ask, GET, for last order-id and all will end up with same. When these users PUT new order, last person to do so wins. Users come to know about failure or success only by GETting the order by order-id and verify it with locally created order. Failed users simply must redo the same sequence till they succeed. Rather if users just let the server know of their intention of creating a new order and the almighty server having wholistic application state would be in better know-how to process the requests. GET / PUT / DELETE or any sequence of it would not be sufficient to express such intent so POST. No wonder it sounds and feels alien.&lt;/p&gt;

&lt;h1&gt;
  
  
  Cache Consistency
&lt;/h1&gt;

&lt;p&gt;Caches introduce a consistency problem though. Say, client has been told to cache a response for few seconds and meanwhile order is ready. Client, based on the cached response, decided to cancel the order. In this case client and server state has diverged. To make it safe to cancel, client can add a condition in the form of If-Match header. Server, in case where the condition does not match simply refuses to process the request telling client that the precondition to honor the request has failed. In the unlikely event, client did not send the If-Match headers, server can still report it as 409 conflict. Or 406 not acceptable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;DELETE /orders/1234
Host: example.org
If-Match: status=Not Ready
Accept: application/vnd.example+xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 412 Precondition failed.
Content-Type:  application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Ready&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;next&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/state-machine”&lt;/span&gt;
    &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;“self”&lt;/span&gt;
    &lt;span class="na"&gt;uri=&lt;/span&gt;&lt;span class="s"&gt;“http://example.org/orders/1234”&lt;/span&gt;
  &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Cancelled the order but Why?
&lt;/h1&gt;

&lt;p&gt;As a business user, wouldn’t you want to know why was the order cancelled? These reasons are beyond api designing and delve more into business asks. If the api has implemented DELETE to cancel the order a typical interaction may look as bellow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;DELETE /orders/1234
Host: example.org
Accept: application/vnd.example+xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 200 Okay
Content-Type:  application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Cancelled&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problem with above interaction is that DELETE does not accept any body. How can we solve this?&lt;/p&gt;

&lt;p&gt;Let’s try using POST&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;POST /orders
Host: example.org
Accept: application/vnd.example+xml


OrderId=14
&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;Operation=Cancel
&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;Reason=Just to annoy you
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 200 Okay
Content-Type:  application/vnd.example+xml


&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://schemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Cancelled&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does not even look right from the get-go. Feels like we are performing a business operation specified by &lt;em&gt;&lt;strong&gt;Operation&lt;/strong&gt;&lt;/em&gt;. Operation is now a keyword which needs to be handled beyond limited set of HTTP verbs. This way the api would keep on adding more and more verbs which need special handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can we do better?
&lt;/h2&gt;

&lt;p&gt;Once we start constraining ourselves to only four verbs which HTTP provides, we can definitely do better. Let's revisit the same problem with the api designing constraints.&lt;/p&gt;

&lt;p&gt;Do not forget that you have limitless supply of nouns. And we are naturally wired to produce random names all the time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;POST /CancelledOrders
Host: example.org
Accept: application/vnd.example+xml


OrderId=14
&lt;span class="err"&gt;&amp;amp;&lt;/span&gt;Reason=Just to annoy you
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 200 Okay
Content-Type:  application/vnd.example+xml

&lt;span class="nt"&gt;&amp;lt;order&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;“http://shemas.example.org/”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;item&lt;/span&gt; &lt;span class="na"&gt;qty=&lt;/span&gt;&lt;span class="s"&gt;“2”&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;ITEM-1&lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;status&amp;gt;&lt;/span&gt;Cancelled&lt;span class="nt"&gt;&amp;lt;/status&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though it sounds simple to come up with names, it is very tedious. No wonder diehard proponent of ReST, Mark Baker or Tim-Berners Lee, suggested to not add any meaning to URI and making them opaque.&lt;/p&gt;

&lt;p&gt;Opaque URIs relieves us from the need to produce new nouns every now and then at the cost of comprehensible api. This also makes documenting the api difficult as api end-points are decided at run-time. Also, security and relevant features can only be useful once the opaque uris are established.&lt;/p&gt;

&lt;p&gt;Roy Fielding, on the other hand, has an opinion that uris are meaningful and it sort of makes more sense. Opaque URIs are for lazy folks.&lt;/p&gt;

&lt;h1&gt;
  
  
  Representations
&lt;/h1&gt;

&lt;p&gt;Now let's focus on Re of ReST. It is not the resource which is sent to the user-agent. User-agent asks for specific type of media it can understand. Let’s consider following HTTP interaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;GET /orders/1234
Host: example.org
Accept: text/plain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reply
&lt;/h2&gt;

&lt;p&gt;If the web-application does not understand the requested media type, it can simply state this inability as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 415 Unsupported Media Type.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if it does indeed support the requested media type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTTP/1.1 200 Okay
Content-Type: text/plain


Order 1234 is not ready
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If user-agent requests for media types which are supported by the web application, it can send the resource data fitting the requested media type. Here it is the same resource but formatted as different media types and all these variations of same resource is called representations. Since the data which flows between the user-agent and the server can be different representations, it is known as Representational State Transfer or simply ReST.&lt;/p&gt;

&lt;p&gt;Further Reading&lt;br&gt;
&lt;a href="https://ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf?ref=hackernoon.com" rel="noopener noreferrer"&gt;Roy Fielding’s dissertation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rest</category>
      <category>restapi</category>
      <category>architecture</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
