<?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[Prince's blog]]></title><description><![CDATA[Associate Software Engineer @WatchguardTechnologies | Maintainer &amp; TSC Member at @AsyncAPI. I turn coffee into code, and bugs into blogs.]]></description><link>https://princerajpoot.com</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 19:59:06 GMT</lastBuildDate><atom:link href="https://princerajpoot.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Blog 1 | Crafting an API Endpoint | at @AsyncAPI]]></title><description><![CDATA[First and foremost, I want to extend my gratitude to my mentor, David Pereira, for his invaluable guidance throughout this journey. I'm immensely grateful for his assistance and mentorship. Working with him has been a fantastic opportunity for me. Ad...]]></description><link>https://princerajpoot.com/crafting-an-api-endpoint</link><guid isPermaLink="true">https://princerajpoot.com/crafting-an-api-endpoint</guid><category><![CDATA[Mentorship Program]]></category><category><![CDATA[AsyncApi]]></category><category><![CDATA[API Endpoint]]></category><dc:creator><![CDATA[Prince Rajpoot]]></dc:creator><pubDate>Mon, 21 Aug 2023 19:09:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1692641273117/2f051507-08d0-4656-b7b1-7c1788e2672b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>First and foremost, I want to extend my gratitude to my mentor, <a target="_blank" href="https://www.linkedin.com/in/jos%C3%A9-david-pereira-13ba5315a/"><strong>David Pereira</strong></a>, for his invaluable guidance throughout this journey. I'm immensely grateful for his assistance and mentorship. Working with him has been a fantastic opportunity for me. Additionally, I’d like to extend my heartfelt thanks to my sister, <a target="_blank" href="https://www.linkedin.com/in/princyrajpoot/"><strong>Princy Rajpoot</strong></a>, for her tremendous support throughout this journey.</p>
<p>Now, let’s delve into the details of the project.</p>
<h2 id="heading-my-project-idea">My Project Idea</h2>
<p>My project idea is to develop an endpoint, tentatively named <code>help/{command}</code>, which will provide users with instructions corresponding to a given command. The primary <code>help</code> endpoint would list all available endpoints, whereas specific commands like <code>help/generate</code> would return detailed information about that particular command, such as available templates and parameters.</p>
<h2 id="heading-getting-started-with-server-api">Getting Started with <code>server-api</code></h2>
<p>My journey began with a deep dive into the <code>server-api</code> project. Analyzing the codebase, I identified six existing endpoints: <code>/validate, /parse, /generate, /convert, /bundle, /diff</code></p>
<p>Upon familiarizing myself with these endpoints, I proceeded to set up the project locally. Interestingly, all existing endpoints employ the <code>POST</code> method. Hence, to invoke them, one must use <code>POSTMAN</code>. Since they all use the <code>POST</code> method, sending a <code>request body</code> is essential to obtain a response.</p>
<p>Having successfully set up the project on my local machine, I delved deeper into understanding its codebase, the overarching project structure, and its inherent workflow.</p>
<h2 id="heading-designing-the-help-endpoint-key-decisions">Designing the <code>/help</code> Endpoint: Key Decisions</h2>
<p>I began thinking about the structure of the <code>/help</code> endpoint. Given that our objective is to provide help for multiple endpoints, let's start by considering how we would pass data to the <code>/help</code> endpoint. The project idea already suggests utilizing the <code>URL approach</code>, as <strong>indicated by</strong><code>help/{command}</code>. You might be wondering why the project idea leaned in that direction, especially when the <code>request body</code> is such a viable option. Let's first understand the differences between the two, and then delve into why we chose <code>URL</code> over the <code>request body</code>.</p>
<ul>
<li><p><code>URL-based</code> data transmission is ideal when:</p>
<ul>
<li><p>The data amount is small, ensuring URLs don’t get too lengthy.</p>
</li>
<li><p>The information isn't sensitive. For context, transmitting sensitive data, like passwords, in URLs can expose them.</p>
</li>
</ul>
</li>
<li><p><code>Request body</code> data transmission becomes crucial when:</p>
<ul>
<li><p>Data size exceeds the URL’s character limit (usually around 2048 characters).</p>
</li>
<li><p>There's a need to send confidential information, which won't be visible in the URL.</p>
</li>
</ul>
</li>
</ul>
<p>Considering both the non-sensitive nature of the data and its compactness, using the <code>URL method</code> is the best choice.</p>
<h2 id="heading-enhance-user-experience">Enhance User Experience</h2>
<p>Enhance user experience by <strong>providing relative links</strong> to all the endpoints directly within the <code>/help</code> section, which contains a list of all the endpoints. Here is a snippet of <code>/help</code> response:</p>
<pre><code class="lang-json">[
    ...

    {
        <span class="hljs-attr">"command"</span>: <span class="hljs-string">"parse"</span>,
        <span class="hljs-attr">"url"</span>: <span class="hljs-string">"/help/parse"</span>
    },
    {
        <span class="hljs-attr">"command"</span>: <span class="hljs-string">"generate"</span>,
        <span class="hljs-attr">"url"</span>: <span class="hljs-string">"/help/generate"</span>
    }

    ...
]
</code></pre>
<p>Users can now conveniently click on links like <code>/help/generate</code> to access specific functionalities, making navigation straightforward and user-friendly.</p>
<h2 id="heading-ensuring-flexibility">Ensuring Flexibility</h2>
<p>During discussions with my mentor <strong>David</strong>, he highlighted that <strong>hardcoding data for the help command wasn’t ideal.</strong> Instead, sourcing it from a GitHub repository would facilitate easier updates and maintenance. Therefore, I decided to source our <code>/help</code> data from GitHub repo.</p>
<h2 id="heading-debugging-dilemmas-the-unexpected-rate-limit-riddle">Debugging Dilemmas: The Unexpected Rate Limit Riddle</h2>
<p>After researching and building the MVP structure, I delved deep into the testing and debugging stage. Full of confidence in my code, I encountered an unexpected hurdle. Initially, I was met with an error, and while troubleshooting it, another error cropped up — all within the confines of my previous codebase. The scenario was mystifying. It was like playing a game of digital whack-a-mole. 🤔</p>
<p>I decided to step back for a moment. After a calming tea break, I revisited the issue with a renewed mindset. Much to my surprise, the root cause wasn't a glitch in my code but an external limitation I hadn't accounted for: the <strong>GitHub API's rate limit</strong>. I had inadvertently overlooked GitHub's rate restriction of 60 requests per hour for each user. Amid my enthusiasm to refine the endpoint, I quickly consumed these requests, resulting in the unforeseen errors.</p>
<p><strong>But here's the twist</strong>: I was in a race against time, needing to test repeatedly. While I couldn't beat time, I found a way to switch my user identity. 😄 Wondering how? By using a <code>VPN</code>, I was able to mask my IP address. This trick allowed me to simulate different users, bypassing the rate limit. A little creative problem-solving, and I was back on track, proving once again that there’s always a way around a roadblock, sometimes just by changing lanes!😌</p>
<h2 id="heading-current-progress">Current Progress 🏗️</h2>
<p>As of now, I'm in the process of finalizing the <strong>structure</strong> and <strong>defining the data</strong> for all the commands.</p>
<p>To facilitate this, I've employed <code>axios.get()</code> to fetch the <code>openapi.yml</code> file of the project, which contains essential data for the help command.</p>
<p>Here's a brief on the tools and libraries in use:</p>
<ul>
<li><p><strong>Axios</strong>: It's a promise-based HTTP client that's both lightweight and efficient. I've specifically used it to make an HTTP request to GitHub's API and retrieve the raw contents of the <code>openapi.yml</code> file.</p>
</li>
<li><p><strong>js-yaml</strong>: YAML is a human-friendly data format widely adopted for configuration files and data storage/transmission. The <code>js-yaml</code> library facilitates the parsing and stringifying of YAML content. With its <code>yaml.load()</code> function, I've converted the raw YAML content (fetched using <code>Axios</code>) into a workable JavaScript object. This transformed object now serves as the foundation for subsequent operations in the endpoint, such as <strong>resolving references</strong> and <strong>pinpointing matching paths</strong>.</p>
</li>
</ul>
<h2 id="heading-whats-next">What’s next?</h2>
<p>In my next blog post, I’ll explore different challenges faced. As this phase wraps up, my attention will shift towards <code>creating unit tests.</code></p>
<p>Till next time,</p>
<p>Prince✌️</p>
]]></content:encoded></item></channel></rss>