<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rochelle Martins' Blog]]></title><description><![CDATA[Rochelle Martins' Blog]]></description><link>https://roch25.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 14:51:56 GMT</lastBuildDate><atom:link href="https://roch25.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Everything about RESTful APIs]]></title><description><![CDATA[REST Explained: A Beginner's Guide to RESTful APIs]]></description><link>https://roch25.hashnode.dev/everything-about-restful-apis</link><guid isPermaLink="true">https://roch25.hashnode.dev/everything-about-restful-apis</guid><dc:creator><![CDATA[Rochelle Martins]]></dc:creator><pubDate>Mon, 19 Oct 2026 06:42:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/60eff8ca23b128642163c82a/1d83377e-0b95-428a-a1f3-87214803c8ed.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What is REST?</h2>
<p>REST is an <strong>architectural style</strong> used to design web services that allow clients and servers to exchange information over a network.  </p>
<p>REST stands for Representational State Transfer.  </p>
<p>Let's break that down.  </p>
<p>Re - <strong>Representational</strong> - A representation is the format in which a resource's information is sent from a server to a client.</p>
<p>Let's say the information stored is a student. When a client requests this student's information, the server can send a representation of the student in JSON format.</p>
<pre><code class="language-python">{
  "id": 101,
  "name": "Rahul",
  "status": "Active"
}
</code></pre>
<p>The client receives this representation rather than directly accessing the server's database.  </p>
<p>S<strong>tate</strong> refers to the information or condition of a resource at a particular moment.  </p>
<p>Later, the student's status might change to <code>"Graduated"</code>.</p>
<p>The resource's state has changed, and a subsequent request can return a new representation reflecting that change.</p>
<p><strong>Transfer</strong> means sending a resource's representation between a client and a server over a network.</p>
<h2>What is a RESTful API?</h2>
<p>A RESTful API is an Application Programming Interface designed according to the principles of REST (Representational State Transfer).</p>
<h2>Principles of REST</h2>
<p>REST follows six architectural principles that help developers build web APIs that are simple, scalable, and easy to maintain.</p>
<ol>
<li><p>Client-Server<br />The client handles the user interface, while the server manages data and business logic. Both can work independently.<br /><strong>Example</strong>: A shopping app displays products, while the server provides product information.</p>
</li>
<li><p>Statelessness<br />Every request must contain the information needed to process it. The server does not depend on remembering previous requests.<br /><strong>Example</strong>: Each API request includes the necessary authentication credentials.</p>
</li>
<li><p>Cacheability<br />Responses can be stored and reused when caching is permitted, reducing repeated requests and improving performance.<br /><strong>Example</strong>: A browser temporarily stores product information instead of requesting it every time.</p>
</li>
<li><p>Uniform Interface<br />The API follows consistent rules for identifying and interacting with resources.<br /><strong>Example</strong>: GET /products/10 retrieves information about product 10.</p>
</li>
<li><p>Layered System<br />The client can communicate with the server through intermediary components without needing to know the internal architecture.<br /><strong>Example</strong>: An API gateway checks requests before forwarding them to the server.</p>
</li>
<li><p>Code on Demand (Optional)<br />The server can send executable code to the client to extend its functionality. This principle is optional.<br /><strong>Example</strong>: A server sends JavaScript that a browser can execute.</p>
</li>
</ol>
<p>HTTP methods define the type of action a client wants to perform on a resource through an API. They help the server understand whether the client wants to retrieve, create, update, or delete data.</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Purpose</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td>GET</td>
<td>Retrieve data</td>
<td>View products</td>
</tr>
<tr>
<td>POST</td>
<td>Create a resource</td>
<td>Add a product</td>
</tr>
<tr>
<td>PUT</td>
<td>Create or replace a resource</td>
<td>Replace product details</td>
</tr>
<tr>
<td>PATCH</td>
<td>Partially update a resource</td>
<td>Change a product's price</td>
</tr>
<tr>
<td>DELETE</td>
<td>Remove a resource</td>
<td>Delete a product</td>
</tr>
</tbody></table>
<h2></h2>
<p>REST API Endpoints  </p>
<p>An API endpoint is a specific URL through which a client can access a resource or interact with a server.</p>
<p>In a RESTful API, endpoints are used to access resources such as users, products, orders, or student records. The client sends an HTTP request to an endpoint, and the server processes the request and returns an appropriate response.</p>
<p>Eg.<br /><a href="https://api.example.com/products/10">https://api.example.com/products/10</a>  </p>
<table>
<thead>
<tr>
<th>Component</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>https://</code></td>
<td>The communication scheme</td>
</tr>
<tr>
<td><a href="http://api.example.com"><code>api.example.com</code></a></td>
<td>The server's domain</td>
</tr>
<tr>
<td><code>/products</code></td>
<td>The product resource collection</td>
</tr>
<tr>
<td><code>/10</code></td>
<td>Identifies a specific product</td>
</tr>
</tbody></table>
<h2>Types of REST API Endpoints</h2>
<p>Collection endpoint</p>
<pre><code class="language-plaintext">GET /products
</code></pre>
<p>Individual resource endpoint</p>
<pre><code class="language-plaintext">GET /products/10
</code></pre>
<p>Related resource endpoint</p>
<pre><code class="language-plaintext">GET /products/10/reviews
</code></pre>
<h2>Endpoints with Query Parameters</h2>
<p>Sometimes a client needs specific results rather than an entire collection. Query parameters can help filter, sort, or paginate the results.</p>
<pre><code class="language-plaintext">GET /products?sort=price&amp;order=asc
</code></pre>
<h3></h3>
<p>Best Practices for Designing REST API Endpoints</p>
<p>When designing endpoints, developers should follow a few common conventions:</p>
<ul>
<li><p>Use nouns for resources: Prefer /products over /getProducts.</p>
</li>
<li><p>Use plural names consistently: For example, /users and /orders.</p>
</li>
<li><p>Use path parameters for specific resources: For example, /users/101.</p>
</li>
<li><p>Use query parameters for filtering: For example, /products?category=books.</p>
</li>
<li><p>Use HTTP methods for operations: Avoid putting action names such as /deleteProduct/10 into URLs when a resource-oriented endpoint with DELETE is more appropriate.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[JavaScript Function methods  - call(), apply(), bind()]]></title><description><![CDATA[Because functions are Function objects, they come equipped with powerful built-in methods such as call(), apply(), and bind().]]></description><link>https://roch25.hashnode.dev/javascript-function-methods-call-apply-bind</link><guid isPermaLink="true">https://roch25.hashnode.dev/javascript-function-methods-call-apply-bind</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Rochelle Martins]]></dc:creator><pubDate>Sat, 11 Oct 2025 05:06:02 GMT</pubDate><content:encoded><![CDATA[<p>Every function in JavaScript is a <strong>Function object</strong>.</p>
<details><summary>Function object</summary><div data-type="detailsContent">In essense, functions themselves are <strong>objects with callable behavior</strong>. Because functions are <code>Function</code> objects, they come equipped with powerful built-in methods such as <code>call()</code>, <code>apply()</code>, and <code>bind()</code>— each of which lets you explicitly control how and where a function is executed, and more importantly, what <code>this</code> refers to within it.</div></details>

<p>We shall discuss three of its methods -</p>
<ul>
<li><p><em>call()</em></p>
</li>
<li><p><em>apply()</em></p>
</li>
<li><p><em>bind()</em></p>
</li>
</ul>
<h2 id="heading-call"><em>call()</em></h2>
<p>Syntax</p>
<pre><code class="lang-javascript">call(thisArg, arg1, ... , argN)
</code></pre>
<h4 id="heading-parameters">Parameters</h4>
<p><code>thisArg</code>: Object to be used as current object</p>
<p><code>arg1, ... , argN</code>: Comma-separated list of arguments to be passed to the function</p>
<h4 id="heading-example">Example</h4>
<p>Let's dissect the <code>call()</code> method using a simple example.</p>
<p>Consider an object <code>person</code> that has a property <code>name</code> and a method <code>feedDog</code></p>
<p><img src="https://sdmntprcentralus.oaiusercontent.com/files/00000000-3eb8-61f5-b171-5a5b8aa231fd/raw?se=2025-10-11T05%3A48%3A33Z&amp;sp=r&amp;sv=2024-08-04&amp;sr=b&amp;scid=2782b823-d84d-595c-b59f-0610c7715530&amp;skoid=03727f49-62d3-42ac-8350-1c0e6559d238&amp;sktid=a48cca56-e6da-484e-a814-9c849652bcb3&amp;skt=2025-10-10T21%3A47%3A47Z&amp;ske=2025-10-11T21%3A47%3A47Z&amp;sks=b&amp;skv=2024-08-04&amp;sig=NCJcgfSKPlTYCuTC8mgVP1g1sdoz7hfNYNlPCOuwv/o%3D" alt="Generated image" class="image--center mx-auto" /></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
   <span class="hljs-attr">name</span>: <span class="hljs-string">"Sally"</span>,
   feedDog() {
       <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.name, <span class="hljs-string">"feeds the dog"</span>);
   }
}
</code></pre>
<p>Consider another object <code>neighbor</code> with a property <code>name</code>. Note that neighbor does not feed the dog and hence, it has no method called <code>feedDog</code></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> neighbor = {
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Jon"</span>,
}
</code></pre>
<p>Now, let's say on a certain day <code>person</code> is not available and so asks her neighbor to feed the dog.</p>
<p><code>neighbor</code> has no method called <code>feedDog</code> so it borrows <code>person</code>'s <code>feedDog</code> method</p>
<pre><code class="lang-javascript">person.feedDog.call(neighbour)
<span class="hljs-comment">// Jon feeds the dog</span>
</code></pre>
<p>The above line of code <em>calls</em> <code>person.feedDog</code> on the the neighbor object. So <code>this</code> now refers to the neighbor object so this.name resolves to Jon</p>
<p>The params following <code>thisArg</code> are arguments to the function.</p>
<p>Let's modify the person.feedDog to accept two arguments:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
   <span class="hljs-attr">name</span>: <span class="hljs-string">"Sally"</span>,
   feedDog(numberOfBowls) {
       <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.name, <span class="hljs-string">"feeds the dog"</span>, foodItem, <span class="hljs-string">"at"</span>, time);
   }
}
</code></pre>
<pre><code class="lang-javascript">person.feedDog.call(neighbour, <span class="hljs-string">"chimken"</span>, <span class="hljs-string">"12 noon"</span>)
<span class="hljs-comment">// Jon feeds the dog chimken at 12 noon</span>
</code></pre>
<p>In summary, the <code>call()</code> method lets you <strong>borrow functions</strong> from one object and use them with another by explicitly setting what <code>this</code> refers to.<br />It executes the function <strong>immediately</strong> and accepts arguments <strong>individually</strong> rather than as an array.</p>
<hr />
<h2 id="heading-apply"><em>apply()</em></h2>
<p>The <code>apply()</code> method is similar to <code>call()</code>, except that it takes <strong>arguments as an array (or array-like object)</strong> rather than a comma-separated list.</p>
<p><strong>Syntax</strong></p>
<pre><code class="lang-javascript">apply(thisArg, [argsArray])
</code></pre>
<p><strong>Parameters</strong></p>
<ul>
<li><p><code>thisArg</code>: Object to use as the current object (<code>this</code>) inside the function.</p>
</li>
<li><p><code>argsArray</code>: Array (or array-like object such as <code>arguments</code>) containing arguments to pass to the function.</p>
</li>
</ul>
<p><strong>Example</strong></p>
<p>Let’s use the same setup:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
   <span class="hljs-attr">name</span>: <span class="hljs-string">"Sally"</span>,
   feedDog(foodItem, time) {
       <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.name, <span class="hljs-string">"feeds the dog"</span>, foodItem, <span class="hljs-string">"at"</span>, time);
   }
}

<span class="hljs-keyword">const</span> neighbor = {
   <span class="hljs-attr">name</span>: <span class="hljs-string">"Jon"</span>
};
</code></pre>
<p>Now, instead of calling with individual arguments, we’ll use <code>apply()</code> with an array:</p>
<pre><code class="lang-javascript">person.feedDog.apply(neighbor, [<span class="hljs-string">"chimken"</span>, <span class="hljs-string">"12 noon"</span>]);
<span class="hljs-comment">// Jon feeds the dog chimken at 12 noon</span>
</code></pre>
<p>The result is <strong>identical</strong> to <code>call()</code>, but the <strong>way arguments are passed</strong> is different.</p>
<p><strong>When to use</strong> <code>apply()</code></p>
<ul>
<li><p>When your arguments are already in an array form.</p>
</li>
<li><p>When you don’t want to manually unpack or spread them.</p>
</li>
</ul>
<p>A common use case is when <strong>using built-in functions like</strong> <code>Math.max</code>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">8</span>, <span class="hljs-number">2</span>];
<span class="hljs-keyword">const</span> max = <span class="hljs-built_in">Math</span>.max.apply(<span class="hljs-literal">null</span>, numbers);
<span class="hljs-built_in">console</span>.log(max); <span class="hljs-comment">// 8</span>
</code></pre>
<hr />
<h2 id="heading-bind"><strong><em>bind()</em></strong></h2>
<p>While <code>call()</code> and <code>apply()</code> <strong>invoke</strong> the function immediately, <code>bind()</code> <strong>returns a new function</strong> with a permanently bound <code>this</code> value.</p>
<p><strong>Syntax</strong></p>
<pre><code class="lang-javascript">bind(thisArg, arg1, ..., argN)
</code></pre>
<p><strong>Parameters</strong></p>
<ul>
<li><p><code>thisArg</code>: The object to be used as <code>this</code> when the function is called.</p>
</li>
<li><p><code>arg1, ..., argN</code>: Optional arguments to pre-set (partial application).</p>
</li>
</ul>
<p><strong>Example</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
   <span class="hljs-attr">name</span>: <span class="hljs-string">"Sally"</span>,
   feedDog(foodItem, time) {
       <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.name, <span class="hljs-string">"feeds the dog"</span>, foodItem, <span class="hljs-string">"at"</span>, time);
   }
}

<span class="hljs-keyword">const</span> neighbor = { <span class="hljs-attr">name</span>: <span class="hljs-string">"Jon"</span> };

<span class="hljs-comment">// Bind returns a new function</span>
<span class="hljs-keyword">const</span> feedByNeighbor = person.feedDog.bind(neighbor, <span class="hljs-string">"chimken"</span>, <span class="hljs-string">"12 noon"</span>);

<span class="hljs-comment">// The function isn’t executed yet</span>
feedByNeighbor(); <span class="hljs-comment">// Jon feeds the dog chimken at 12 noon</span>
</code></pre>
<p>The <code>feedByNeighbor</code> function retains the context of <code>neighbor</code> no matter where it is called.</p>
<p>This is especially useful when passing methods as <strong>callbacks or event handlers</strong>, where <code>this</code> may otherwise get lost.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> button = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"button"</span>);
button.addEventListener(<span class="hljs-string">"click"</span>, person.feedDog.bind(person, <span class="hljs-string">"kibble"</span>, <span class="hljs-string">"7 am"</span>));
</code></pre>
<p>Without <code>bind()</code>, <code>this</code> would refer to the button element instead of <code>person</code>.</p>
<hr />
<h2 id="heading-summary-call-vs-apply-vs-bind">Summary: <code>call()</code> vs <code>apply()</code> vs <code>bind()</code></h2>
<p>All three methods—<code>call()</code>, <code>apply()</code>, and <code>bind()</code>—allow you to <strong>manually control the value of</strong> <code>this</code> in JavaScript.</p>
<ul>
<li><p>Use <code>call()</code> when you know the exact arguments.</p>
</li>
<li><p>Use <code>apply()</code> when arguments are in an array.</p>
</li>
<li><p>Use <code>bind()</code> when you need to preserve context for later execution.</p>
</li>
</ul>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Method</td><td>Invokes Immediately</td><td>Arguments Format</td><td>Returns a Function</td><td>Common Use Case</td></tr>
</thead>
<tbody>
<tr>
<td><strong>call()</strong></td><td>Yes</td><td>Comma-separated</td><td>No</td><td>Direct invocation with known args</td></tr>
<tr>
<td><strong>apply()</strong></td><td>Yes</td><td>Array or array-like</td><td>No</td><td>Invoking with dynamic/array args</td></tr>
<tr>
<td><strong>bind()</strong></td><td>No</td><td>Comma-separated</td><td>Yes</td><td>Preserving <code>this</code> for later calls</td></tr>
</tbody>
</table>
</div><p><img src="https://sdmntprnortheu.oaiusercontent.com/files/00000000-acd8-61f4-9d3e-fab89907f469/raw?se=2025-10-11T06%3A03%3A22Z&amp;sp=r&amp;sv=2024-08-04&amp;sr=b&amp;scid=231b637c-4ce8-5143-8ea4-2748c1d5a3d3&amp;skoid=03727f49-62d3-42ac-8350-1c0e6559d238&amp;sktid=a48cca56-e6da-484e-a814-9c849652bcb3&amp;skt=2025-10-10T23%3A07%3A21Z&amp;ske=2025-10-11T23%3A07%3A21Z&amp;sks=b&amp;skv=2024-08-04&amp;sig=OfBtU0Wj%2BU95I7gnMQSJDXbKIzk/vZ/RthN/9yVGijY%3D" alt /></p>
]]></content:encoded></item></channel></rss>