<?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: Rohit Sharma</title>
    <description>The latest articles on DEV Community by Rohit Sharma (@rohitsharmaj7).</description>
    <link>https://dev.to/rohitsharmaj7</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F306487%2F3f0d8a44-3842-438f-a522-6b5b2a12773d.jpeg</url>
      <title>DEV Community: Rohit Sharma</title>
      <link>https://dev.to/rohitsharmaj7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohitsharmaj7"/>
    <language>en</language>
    <item>
      <title>Rest &amp; Restfulness API Design Principles</title>
      <dc:creator>Rohit Sharma</dc:creator>
      <pubDate>Thu, 18 Jun 2026 01:43:54 +0000</pubDate>
      <link>https://dev.to/rohitsharmaj7/rest-restfulness-api-design-principles-3if4</link>
      <guid>https://dev.to/rohitsharmaj7/rest-restfulness-api-design-principles-3if4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Re&lt;/strong&gt;presentational &lt;strong&gt;S&lt;/strong&gt;tate &lt;strong&gt;T&lt;/strong&gt;ransfer is an architectural style used for designing the network applications. Instead of relying on complex protocols REST relies on standard web protocols like HTTP to enable communication between clients and server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If Definition seems complex to you, no worries let's breakdown the word &lt;br&gt;
REST = Representation State Transfer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose you have a user resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This actual resource, exists on the server i.e. database row containing all the information about user with id 7.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REPRESENTATION&lt;/strong&gt; The server doesn't send the actual database row. It sends just a representation of the resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Rohit"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This JSON is a representation of the user's current state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STATE TRANSFER&lt;/strong&gt; When the client requests&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET users/7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server transfers representation of this resource's state to the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Server State
        ⬇️
JSON Representation
        ⬇️
Transferred over HTTP
        ⬇️
      Client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's where the term &lt;strong&gt;Representational state transfer&lt;/strong&gt; comes from.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main Idea behind REST:&lt;/strong&gt; It operates on stateless communication which means that each request from client contains all the necessary information and server does not store any session data between requests. This makes REST very scalable, reliable and easy to implement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why REST matters?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity &amp;amp; Scalability:&lt;/strong&gt; Rest is build on standard HTTP protocols like GET, PUT, POST and DELETE making it easy to understand and implement. Because REST follow stateless architecture it scales efficiently, allowing multiple servers to handle requests without maintaining session data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interoperability:&lt;/strong&gt; REST APIs are platform independent which means they can be consumed by clients running on different devices, different Operating Systems and implemented in different programming languages. Whether its a mobile application or web application, REST can be used everywhere.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; By leveraging caching REST can introduce lower latency which contribute towards enhancing performance.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/product/&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;productService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public, max-age=300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//this tells clients, browsers, CDNs, reverse proxies &amp;amp; API Gateways: You may cache this response for 300 seconds&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;REST's cachebility constraint is typically implemented by sending HTTP cache headers such as Cache-Control, ETag or expires. These headers allow clients to cache responses, reducing the latency and backend loads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RESTful API Design Principles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not every API using HTTP is RESTful, A RESTful API is an API that follows REST principles correctly. So, below are the design principles of a perfect REST API:&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Resource-Based URLs:&lt;/strong&gt; Resources should be nouns, not verbs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;❌BAD&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /getUsers
POST /createUser
DELETE /deleteUser/101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;✅GOOD&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /users
POST /users
DELETE /users/101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;strong&gt;Use HTTP methods properly&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET    /users       -&amp;gt; Fetch users
POST   /users       -&amp;gt; Create user
PUT    /users/101   -&amp;gt; Replace user
PATCH  /users/101   -&amp;gt; Update user
DELETE /users/101   -&amp;gt; Delete user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;strong&gt;Statelessness:&lt;/strong&gt; Every request should contain all information needed. Server should not remember previous requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /orders
Authorization: Bearer JWT_TOKEN

//The JWT carries user identity. Server doesn't need session memory.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.&lt;strong&gt;Client-Server Separation:&lt;/strong&gt; Frontend and backend are independent. Frontend can change without changing backend&lt;br&gt;
5.&lt;strong&gt;Cacheable Responses:&lt;/strong&gt; Frequently accessed data can be cached, which eventually reduces latency and improves performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of perfect RESTful User API&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET    /users
GET    /users/101
POST   /users
PUT    /users/101
PATCH  /users/101
DELETE /users/101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is considered RESTful because:&lt;/p&gt;

&lt;p&gt;✅ Resources are nouns&lt;br&gt;
✅ Correct HTTP methods used&lt;br&gt;
✅ Stateless&lt;br&gt;
✅ Consistent URL design&lt;/p&gt;

</description>
      <category>restapi</category>
      <category>restfulness</category>
      <category>api</category>
      <category>rest</category>
    </item>
  </channel>
</rss>
