<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditi on Medium]]></title>
        <description><![CDATA[Stories by Aditi on Medium]]></description>
        <link>https://medium.com/@addyhebbar90?source=rss-ca808ad35664------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kf4YZRG4Llr_gSX2nm6SJg.jpeg</url>
            <title>Stories by Aditi on Medium</title>
            <link>https://medium.com/@addyhebbar90?source=rss-ca808ad35664------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:38:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@addyhebbar90/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cannot Find Module: The Error That Taught Me More Than the Tutorial Did]]></title>
            <link>https://medium.com/@addyhebbar90/cannot-find-module-the-error-that-taught-me-more-than-the-tutorial-did-551815a09363?source=rss-ca808ad35664------2</link>
            <guid isPermaLink="false">https://medium.com/p/551815a09363</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Aditi]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 15:53:21 GMT</pubDate>
            <atom:updated>2026-08-07T15:53:21.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leJNvhjdMexMGTK47bdFtA.png" /></figure><p>Today’s post is a smaller one no big REST theory, just a debugging session that ended up teaching me more about how a Node backend actually fits together than any explanation could have.</p><h3>The error</h3><p>I’ve been building a small weather API in TypeScript and Express, and I finally split it into proper files: routes, controllers, the works. The moment I did that, I hit this:</p><pre>Cannot find module &#39;../controllers/weatherController&#39;</pre><p>Honestly my first reaction was mild panic, but this turned out to be one of those errors every backend dev runs into at some point. It just means Express is trying to import weatherController and can&#39;t locate the file.</p><h3>What I actually checked</h3><p>Instead of guessing, I went through it in order.</p><p><strong>Does the file exist?</strong> Inside src/, I needed:</p><pre>src/<br>├── controllers/<br>│   └── weatherController.ts</pre><p><strong>Does the folder name match exactly?</strong> controllers, not controller or Controllers. Casing and pluralization both matter here, which I did not expect to bite me.</p><p><strong>Does the file name match exactly?</strong> weatherController.ts, not WeatherController.ts, not weathercontroller.ts, not weather-controller.ts. TypeScript module resolution is unforgiving about this.</p><p><strong>Is the import path correct?</strong> In weatherRoutes.ts:</p><pre>import { Router } from &quot;express&quot;;<br>import { getWeather } from &quot;../controllers/weatherController&quot;;</pre><pre>const router = Router();</pre><pre>router.get(&quot;/:city&quot;, getWeather);</pre><pre>export default router;</pre><p><strong>Does the controller actually export the function?</strong> This was the one that got me. I had the function written, but without the export keyword in front of it, Express has nothing to import.</p><pre>import { Request, Response } from &quot;express&quot;;</pre><pre>export const getWeather = (req: Request, res: Response): void =&gt; {<br>  const { city } = req.params;</pre><pre>  res.json({<br>    city,<br>    temperature: 29,<br>    condition: &quot;Cloudy&quot;,<br>    humidity: 82,<br>  });<br>};</pre><p>Once I added export, everything ran again. Small keyword, whole error.</p><h3>What I’ve actually built so far</h3><p>Stacking it up, this is more than it felt like in the moment:</p><ul><li>TypeScript project setup</li><li>Express server</li><li>Clean folder structure</li><li>Routes</li><li>Controllers</li><li>Dynamic route parameters (:city)</li><li>JSON responses</li><li>Fixed an import/module error on my own, without pasting the error into a search bar first</li></ul><h3>Understanding route parameters</h3><p>Before moving on, I tested this myself in Postman:</p><pre>GET http://localhost:3000/weather/bangalore<br>GET http://localhost:3000/weather/mumbai<br>GET http://localhost:3000/weather/chennai</pre><p>The part that changes each time is the city value in the response. The part that stays the same is the structure: temperature, condition, humidity are always there. And the city value itself is coming straight from the URL segment after /weather/, captured by Express as req.params.city. That&#39;s the whole idea of a route parameter: one route definition, many possible values plugged in at request time.</p><h3>The next challenge: basic validation</h3><p>Here’s the thing nobody points out until you hit it yourself. If I request:</p><pre>GET /weather/123</pre><p>my API happily returns:</p><pre>{<br>  &quot;city&quot;: &quot;123&quot;,<br>  &quot;temperature&quot;: 29,<br>  &quot;condition&quot;: &quot;Cloudy&quot;,<br>  &quot;humidity&quot;: 82<br>}</pre><p>Which makes no sense. A city name shouldn’t be pure digits. So the challenge was to catch that case and respond properly instead of pretending it’s valid.</p><p>The approach: check whether the city param is entirely digits using a regex, /^\d+$/, and if it matches, respond with a 400 Bad Request instead of mock data:</p><pre>res.status(400).json({<br>  error: &quot;City name must contain letters.&quot;,<br>});</pre><p>Otherwise, return the weather response like normal.</p><p>I tried implementing it myself before looking anything up, which felt slower in the moment but stuck a lot better than copying a working answer would have.</p><h3>Quick knowledge check I gave myself</h3><p>A few questions to make sure I actually understood this and didn’t just get lucky with copy paste:</p><p><strong>1. What’s the difference between </strong><strong>GET /weather/:city and </strong><strong>GET /weather?city=bangalore?</strong> The first is a route parameter, the city is part of the URL path itself, and the route pattern requires it. The second is a query parameter, it&#39;s optional by nature and sits after the ?. Route params usually make sense when the value is required and identifies &quot;which resource,&quot; query params make more sense for optional filters or settings.</p><p><strong>2. Why use </strong><strong>res.status(400).json() instead of just </strong><strong>res.json()?</strong> Because res.json() alone defaults to a 200 OK status. If the request is genuinely invalid, like a numeric city name, the response needs to say so through the status code, not just through the message body. Clients (and any frontend consuming this) rely on that status code to know whether to treat the response as success or failure.</p><p><strong>3. Where should business logic live? Routes, controllers, or somewhere else?</strong> Controllers. Routes should just map a URL and method to a function, nothing more. Business logic, like validation and eventually calling external services, belongs in the controller (and later, in a service layer once things get more complex).</p><p><strong>4. What does </strong><strong>req.params.city contain for </strong><strong>GET /weather/mumbai?</strong> &quot;mumbai&quot;, exactly as typed in the URL, as a string.</p><h3>What’s coming next</h3><p>The mock data has served its purpose, but the next step is swapping it out for a real, live weather API. That means:</p><ul><li>Calling an actual external API</li><li>Environment variables (.env) so I&#39;m not hardcoding an API key into the codebase</li><li>Using fetch or axios to make the request</li><li>Handling errors properly when the external API fails or times out</li><li>Introducing a services folder, so the controller isn’t doing the actual API-calling work itself</li></ul><p>The architecture is about to grow a layer:</p><pre>Browser/Postman<br>      │<br>      ▼<br>   Routes<br>      │<br>      ▼<br> Controllers<br>      │<br>      ▼<br>  Services<br>      │<br>      ▼<br>Weather API (external)</pre><p>This is the same layered pattern most production Express apps use, and building it by hand instead of just reading about it is finally making it click.</p><p>Small checkpoint, but if the real API integration breaks something next, I’ve got a clean point to come back to. Feels like I’m building this the way an actual backend project gets built, one layer at a time, instead of dumping everything into one file and hoping for the best.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=551815a09363" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Kept Nodding Along to “REST API” Until I Actually Built One]]></title>
            <link>https://medium.com/@addyhebbar90/i-kept-nodding-along-to-rest-api-until-i-actually-built-one-3175d9ead125?source=rss-ca808ad35664------2</link>
            <guid isPermaLink="false">https://medium.com/p/3175d9ead125</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api-design]]></category>
            <dc:creator><![CDATA[Aditi]]></dc:creator>
            <pubDate>Thu, 06 Aug 2026 16:49:21 GMT</pubDate>
            <atom:updated>2026-08-06T16:49:21.895Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-Whg0Z9TB1t8uwzqnm5Lw.png" /></figure><p>For a while, “REST API” was just a term I used without really knowing what made an API “RESTful” versus just an API. I finally sat down, took notes, and worked through it properly, including designing a small weather API as I went. This post is that understanding, written out.</p><h3>So what is REST, really?</h3><p>REST stands for <strong>Re</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer. The important thing to get right away: REST is not a protocol. It’s a set of architectural rules, a style, for how a client and a server should talk to each other over HTTP.</p><p>RESTful just means an API that implements REST constraints. That’s it. No special technology, no special format, just a way of organizing how requests and responses work.</p><p>REST was introduced by Roy Fielding back in 2000, and it caught on because it solved real problems that older styles like SOAP had. SOAP came with a heavy, strict contract (lots of XML), which made it harder for developers to work with. REST, in comparison, is:</p><ul><li><strong>Simple</strong>: resources plus URLs plus HTTP verbs</li><li><strong>Scalable</strong>: stateless servers work well with load balancing and caching</li><li><strong>Interoperable</strong>: any language or platform can speak HTTP</li></ul><h3>Resources are the core idea</h3><p>In REST, everything is a <strong>resource</strong>, meaning any piece of information the API can provide to a client. A resource is identified by a URI (Uniform Resource Identifier), which works like a street address for a house, except instead of a single house, it might point to a whole collection of them.</p><p>For example:</p><pre>GET /users/7</pre><p>/users is the collection, 7 is a specific user&#39;s ID. The URI tells the client <em>where</em> the resource lives, and the HTTP method tells the server <em>what to do</em> with it.</p><h3>HTTP methods = CRUD</h3><p>Once you think in terms of resources, the HTTP methods map cleanly onto CRUD operations:</p><ul><li><strong>GET</strong>: Read data. Example: GET /orders reads all orders</li><li><strong>POST</strong>: Create data. Example: POST /orders creates a new order</li><li><strong>PUT</strong>: Update data. Example: PUT /orders/23 updates order 23</li><li><strong>DELETE</strong>: Delete data. Example: DELETE /orders/23 deletes order 23</li></ul><p>Server replies come with status codes that tell you what happened, like 200 OK, 201 Created, or 404 Not Found. Data usually travels in JSON.</p><h3>Worked example: a weather API</h3><p>I found it easier to internalize this by designing a small weather app API myself.</p><p>For a 5-day forecast of <em>one</em> city, everything is read-only, so GET is all you need:</p><pre>GET /weather/{city}/forecast?days=5</pre><p>For tracking <em>multiple</em> favorite cities, the pattern changes because now you’re managing your own data, not just reading external weather data:</p><ul><li>POST /favorites adds a new favorite city</li><li>PUT /favorites/{id} fixes a typo or changes the city</li><li>DELETE /favorites/{id} removes a city</li><li>GET /favorites lists saved cities</li><li>GET /favorites/{id}/forecast gets the forecast for that saved city</li></ul><p>The distinction that clicked for me here: <strong>weather data itself is read-only</strong> (GET only), while <strong>your list of favorite cities is user data you own</strong> (so it gets full CRUD). REST isn’t just “use all four verbs everywhere,” it’s about matching the verb to what’s actually happening to the resource.</p><h3>Designing the JSON response</h3><p>The other half of API design is deciding what the response body actually looks like. For GET /weather/{city}/forecast, a clean shape looks like this:</p><pre>{<br>  &quot;city&quot;: &quot;Bengaluru&quot;,<br>  &quot;country&quot;: &quot;IN&quot;,<br>  &quot;days&quot;: [<br>    {<br>      &quot;date&quot;: &quot;2026-08-07&quot;,<br>      &quot;min_temp&quot;: 22.5,<br>      &quot;max_temp&quot;: 28.0,<br>      &quot;description&quot;: &quot;Light rain&quot;,<br>      &quot;humidity&quot;: 78,<br>      &quot;wind_speed&quot;: 4.2<br>    }<br>  ]<br>}</pre><p>A few rules I kept coming back to:</p><ul><li>Use objects for a single item, arrays for lists (like the days array here, which is perfect for looping in a frontend).</li><li>Pick one naming convention (snake_case or camelCase) and stick with it.</li><li>Keep it flat. Deep nesting makes the frontend’s job harder for no real benefit.</li><li>Do the thinking on the backend, not the frontend. For example, instead of making the frontend calculate “should I show an umbrella icon,” the API can just return &quot;umbrella_advice&quot;: true directly, computed from rain probability server-side. The frontend shouldn&#39;t have to know <em>why</em>, just what to display.</li></ul><h3>JSON, quickly</h3><p>JSON (JavaScript Object Notation) is the standard format REST APIs use to move data around. It’s lightweight and human-readable: just keys and values, and arrays when you need lists.</p><pre>{<br>  &quot;id&quot;: 7,<br>  &quot;name&quot;: &quot;xyz&quot;<br>}</pre><p>That’s really all there is to it. Its simplicity is exactly why it replaced XML as the default for REST APIs.</p><h3>The 6 constraints that make an API “RESTful”</h3><p>This is the part that actually separates REST from “an API that returns JSON.” An API isn’t RESTful just because it uses HTTP and JSON, it has to follow these constraints:</p><p><strong>1. Client-server separation</strong> The client (frontend, mobile app, even Postman) and the server are independent. The client never touches the database directly, it only talks to the server through defined endpoints like /auth/login. This means the same backend can serve a React web app, an Android app, or anything else, without changes.</p><p><strong>2. Statelessness</strong> Every single request must carry all the information needed to process it. The server doesn’t remember anything about you between requests. There’s no “session memory” sitting on the server by default. Each call stands alone.</p><p><strong>3. Uniform interface</strong> All requests and responses follow a consistent, predictable format, regardless of what client is making the call. This is what lets any client talk to any REST server without needing custom logic per client.</p><p><strong>4. Layered system</strong> There can be more servers between the client and the actual backend, like load balancers, security layers, and caching layers, and the client doesn’t need to know or care. As long as the layers don’t change the actual message being passed, they can be added freely.</p><p><strong>5. Cacheable</strong> Server responses should indicate whether they can be cached, and for how long. This matters a lot for something like a mobile app, where re-fetching the same forecast data repeatedly wastes both time and server load.</p><p><strong>6. Code on demand (optional)</strong> The rarely-used one. A REST API can optionally send back executable code that the client runs. This hands some logic to the client instead of keeping everything on the backend. Most APIs skip this entirely.</p><h3>Idempotency</h3><p>One term that took me a moment to actually get: <strong>idempotency</strong>. An operation is idempotent if doing it once or doing it a hundred times produces the <em>same</em> end result on the server.</p><ul><li>GET, PUT, DELETE are idempotent. Calling DELETE /orders/23 five times still just means order 23 is deleted. No extra side effects.</li><li>POST is <strong>not</strong> idempotent. Calling POST /orders five times creates five orders.</li></ul><p>This matters in practice because idempotent methods are “safe to retry.” If a PUT request times out and your client retries it automatically, nothing breaks. Retry a POST automatically, though, and you might create duplicate records.</p><h3>How login actually works in REST (statelessness in practice)</h3><p>This is where “stateless” stops being an abstract rule and becomes something you actually have to design around. If the server doesn’t remember you between requests, how does login even work?</p><p><strong>The request itself:</strong></p><pre>POST /auth/login<br>Body: { &quot;email&quot;: &quot;user@ex.com&quot;, &quot;password&quot;: &quot;secret123&quot; }</pre><p>The server:</p><ol><li>Looks up the user by email in the database</li><li>Checks the password against the hashed version stored there</li><li>If it matches, it needs to somehow tell <em>future</em> requests “this person is logged in,” without storing memory of the conversation</li></ol><p>There are two common ways to solve this.</p><h3>Option A: Cookie + server-side session</h3><p>The server generates a session ID (say, abcd123) and stores the actual session data (user ID, logged-in status, etc.) on its own side, whether that&#39;s in memory, Redis, or a database.</p><p>The response sends that session ID back as a cookie:</p><pre>Status: 200 OK<br>Header: Set-Cookie: session-id=abcd123; HttpOnly; Secure</pre><p>From here, the browser stores that cookie and automatically attaches it to every future request. On each request, the server:</p><ol><li>Reads the session-id from the cookie</li><li>Looks up that session in its own store</li><li>Knows who’s making the request</li></ol><p>Logging out is simple: the server deletes that session record, or the client hits DELETE /auth/session (or POST /auth/logout) and the browser clears the cookie.</p><p>The catch: the server has to store and manage that session data somewhere. That’s a bit of state living server-side, which is why this pattern is often called “server-side session,” even inside an otherwise stateless system.</p><h3>Option B: JWT (token-based)</h3><p>Instead of storing anything server-side, the server encodes the user’s info directly into a signed token and hands the <em>whole thing</em> to the client:</p><pre>Token: eyJhbGciOi...</pre><p>The client stores this (in memory, local storage, etc.) and sends it back on every request, usually in a header:</p><pre>Authorization: Bearer &lt;token&gt;</pre><p>The server never stores this token anywhere. On every request, it just verifies the token’s signature and reads the user info straight out of it. This is what makes JWT a better fit for stateless systems and for things like mobile apps or multiple backend services that need to trust the same token without checking a shared session store.</p><p>Logout is trickier here. Since the server isn’t tracking active tokens, “logging out” usually just means the client deletes the token locally. If you need real server-side invalidation (say, the token was compromised), you need an extra mechanism like a blacklist of revoked tokens.</p><p><strong>Quick comparison:</strong></p><ul><li><strong>Where the state is stored.</strong> Session + Cookie: on the server (session store). JWT: encoded inside the token itself.</li><li><strong>Good for.</strong> Session + Cookie: traditional web apps. JWT: mobile apps, SPAs, multi-service backends.</li><li><strong>Logout.</strong> Session + Cookie: delete the session server-side. JWT: client discards the token locally (or the server maintains a blacklist of revoked tokens).</li></ul><h3>Putting it together</h3><p>What made REST finally click for me wasn’t memorizing the six constraints. It was designing something small (the weather API) and running into the actual decisions: which verb fits which action, what the JSON shape should look like, and how something as “stateless” as REST still manages to keep you logged in. That last part especially, realizing sessions and JWTs are really just two different answers to “how do you fake memory in a system that isn’t supposed to have any,” is what tied the whole thing together for me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3175d9ead125" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>