<?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>Forem: Hillary Ombima</title>
    <description>The latest articles on Forem by Hillary Ombima (@ombima).</description>
    <link>https://forem.com/ombima</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%2F1687217%2Fc333b4b1-0810-4375-98a0-276846619d9d.jpg</url>
      <title>Forem: Hillary Ombima</title>
      <link>https://forem.com/ombima</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ombima"/>
    <language>en</language>
    <item>
      <title>Git Commands You'll Actually Use</title>
      <dc:creator>Hillary Ombima</dc:creator>
      <pubDate>Fri, 31 Oct 2025 09:20:13 +0000</pubDate>
      <link>https://forem.com/ombima/git-commands-youll-actually-use-3ep</link>
      <guid>https://forem.com/ombima/git-commands-youll-actually-use-3ep</guid>
      <description>&lt;p&gt;You know that &lt;em&gt;sinking feeling&lt;/em&gt; when you delete the wrong file? Or when you're trying to merge your teammate's code and suddenly everything's red and broken? Yeah, Git won't prevent those moments, but it'll definitely save you from them.&lt;/p&gt;

&lt;p&gt;I used to think Git was just something you grudgingly learned because everyone else used it. Then I actually started using it properly, and honestly? It changed everything. Suddenly I could experiment without fear, collaborate without chaos, and actually understand what happened to my code last time.&lt;/p&gt;

&lt;p&gt;This isn't going to be one of those boring Git tutorials that dumps 50 commands on you. Instead, we're covering the essentials: the commands you'll actually use daily, explained in plain English. Whether you're brand new to Git or you've been faking it with the same three commands for years, let's get you comfortable with version control.&lt;/p&gt;

&lt;p&gt;So let's start with the basics, the commands that'll become muscle memory.&lt;/p&gt;

&lt;p&gt;1.&lt;code&gt;git init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is how you tell Git "hey, start tracking this project." Run it once in your project folder and Git creates a hidden &lt;code&gt;.git&lt;/code&gt; directory where it stores all your version history.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;myApp
&lt;span class="nb"&gt;cd &lt;/span&gt;myApp
git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your folder is a Git repository. That's it.&lt;/p&gt;

&lt;p&gt;2.&lt;code&gt;git add&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Stages changes in the current directory and sub directories.&lt;/p&gt;

&lt;p&gt;Think of this as preparing your changes for a snapshot. You're telling Git "these are the files I want to include in my next commit." Nothing's permanent yet, you're just staging things.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"# My firs App"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; README.md
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Demo"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; README.md
git add README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pro tip:&lt;/em&gt;&lt;/strong&gt; Use &lt;code&gt;git add .&lt;/code&gt; to stage everything at once, but be careful; you might accidentally include files you didn't mean to (like that &lt;code&gt;secrets.env&lt;/code&gt; file you forgot about).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.&lt;code&gt;git commit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you're taking the snapshot. This saves all your staged changes with a message describing what you did. Think of commits like save points in a video game; you'll thank yourself later when you need to roll back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add README.md
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;&lt;em&gt;-m&lt;/em&gt;&lt;/strong&gt; flag lets you add your message right in the command. Keep it short and descriptive: "Initial commit", "Fix login bug", "Add user dashboard", etc.&lt;/p&gt;

&lt;p&gt;4.&lt;code&gt;git push&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You've made commits locally, but now you need to send them to GitHub (or wherever your remote repository lives). That's what push does, it uploads your local changes to the cloud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"feat: add a new feature"&lt;/span&gt;
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First time pushing to a new branch? Git will probably yell at you and tell you to use &lt;code&gt;git push -u origin branch-name&lt;/code&gt;. Just do what it says, the &lt;code&gt;-u&lt;/code&gt; sets up tracking so future pushes are easier.&lt;/p&gt;

&lt;p&gt;5.&lt;code&gt;git pull&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your teammate just pushed changes. Before you start working, you need to grab their updates and merge them into your local code. That's &lt;code&gt;git pull&lt;/code&gt;, it downloads changes and automatically merges them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
git pull origin main
git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Warning:&lt;/strong&gt;&lt;/em&gt; If you have uncommitted changes and you pull, Git might complain about conflicts. Commit or stash your work first to avoid headaches.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;6.&lt;code&gt;git remote&lt;/code&gt;&lt;br&gt;
This connects your local repository to a remote one (like on GitHub). You'll usually do this once when setting up a project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &amp;lt;url&amp;gt;
git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
git remote rename origin myFirstApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;origin&lt;/code&gt; name is just a convention: it's the default name for your main remote repository. You can call it whatever you want, but everyone uses &lt;code&gt;origin&lt;/code&gt; so... just stick with that.&lt;/p&gt;

&lt;p&gt;7.&lt;code&gt;git branch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Branches let you work on features without touching your main code. Think of them as parallel universes for your project — experiment freely, then merge back when you're ready.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch
git branch feature-UI-layout
git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first &lt;code&gt;git branch&lt;/code&gt; lists all branches. The second creates a new one. The third confirms it was created. You're still on your original branch though — creating doesn't switch you to it.&lt;/p&gt;

&lt;p&gt;8.&lt;code&gt;git fetch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This downloads changes from the remote repository but doesn't merge them into your code. It's like checking what's new without actually integrating it yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git fetch origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt; When you want to see what others have done before deciding to merge. It's the cautious version of &lt;code&gt;git pull&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;9.&lt;code&gt;git checkout&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switches you between branches. It's how you move from one parallel universe to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch
git checkout feature-UI-layout
git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see an asterisk (*) next to the branch you're currently on. Modern Git also has &lt;code&gt;git switch&lt;/code&gt; which does the same thing but is more explicit.&lt;/p&gt;

&lt;p&gt;10.&lt;code&gt;git merge&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You finished your feature branch and now you want to bring those changes back into main. That's what merge does, it combines the histories of two branches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git merge feature-UI-layout
git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Merge conflicts are normal. When Git can't figure out how to combine changes automatically, it asks you to decide. Don't panic: just open the files, pick which changes to keep, and commit the result.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;11.&lt;code&gt;git status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your best friend when you're confused. It shows what files have changed, what's staged, what's not, and which branch you're on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Happy learning git"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; hello.txt
git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this constantly. Seriously. Before commits, after pulls, when things feel weird — &lt;code&gt;git status&lt;/code&gt; is your diagnostic tool.&lt;/p&gt;

&lt;p&gt;12.&lt;code&gt;git reset&lt;/code&gt;&lt;br&gt;
Made a mistake? git reset lets you undo commits and move your branch pointer back in time. Be careful with this one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; &amp;lt;commit-hash&amp;gt;
git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--hard&lt;/code&gt; flag is dangerous — it deletes your changes permanently. Use &lt;code&gt;--soft&lt;/code&gt; if you want to keep the changes but undo the commit. And if you've already pushed, don't reset — use &lt;code&gt;git revert&lt;/code&gt; instead.&lt;/p&gt;

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

&lt;p&gt;These twelve commands will cover 90% of your daily Git usage. You don't need to memorize every flag or option, just understand what each command does and why you'd use it.&lt;/p&gt;

&lt;p&gt;Git gets easier the more you use it. Yeah, you'll mess up sometimes (we all have). But that's fine, Git is designed to handle mistakes. Just keep committing, keep experimenting, and don't be afraid to Google when things get weird. Want to level up your Git skills? Try this interactive practice tool &lt;a href="https://learngitbranching.js.org/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now go forth and version control with confidence. You've got this.&lt;/p&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>From Trust to Consensus: How Stellar Reaches Agreement Without Mining</title>
      <dc:creator>Hillary Ombima</dc:creator>
      <pubDate>Mon, 29 Sep 2025 11:14:47 +0000</pubDate>
      <link>https://forem.com/ombima/from-trust-to-consensus-how-stellar-reaches-agreement-without-mining-941</link>
      <guid>https://forem.com/ombima/from-trust-to-consensus-how-stellar-reaches-agreement-without-mining-941</guid>
      <description>&lt;p&gt;Consensus is what keeps Stellar’s decentralized payment network secure and synchronized. Instead of one central authority approving transactions, many independent nodes (validators) agree on the same version of the ledger. This prevents double-spending and ensures reliability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why SCP?
&lt;/h2&gt;

&lt;p&gt;Unlike &lt;code&gt;Proof of Work&lt;/code&gt; (Bitcoin) or &lt;code&gt;Proof of Stake&lt;/code&gt; (Ethereum and others), Stellar’s SCP is based on &lt;strong&gt;Federated Byzantine Agreement (FBA)&lt;/strong&gt;. Each validator chooses a set of other validators it trusts (its &lt;strong&gt;quorum set&lt;/strong&gt;). Agreement emerges when these trust choices overlap, giving &lt;code&gt;SCP&lt;/code&gt; its open and decentralized nature.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;No mining&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;No staking&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Just trust-based agreement&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Key Terms
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quorum set&lt;/strong&gt; → The list of nodes a validator trusts.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Threshold&lt;/strong&gt; → Minimum number of nodes in that set that must agree.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quorum slice&lt;/strong&gt; → A smaller subset of the quorum set that’s enough to reach agreement.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Federated voting&lt;/strong&gt; → Validators move from &lt;em&gt;voting&lt;/em&gt; → &lt;em&gt;accepting&lt;/em&gt; → &lt;em&gt;confirming&lt;/em&gt; a statement.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safety vs &lt;code&gt;Liveness&lt;/code&gt;&lt;/strong&gt; → SCP prioritizes safety (no conflicting ledgers) over &lt;code&gt;liveness&lt;/code&gt; (progress may pause until consensus is reached).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How SCP Reaches Agreement
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Nomination&lt;/strong&gt; → Nodes propose transaction sets. Over time, they converge on the same candidate set.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ballot protocol&lt;/strong&gt; → Validators vote, prepare, and commit that candidate set until the network locks in a single, agreed ledger.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why It Stands Out
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fast &amp;amp; energy-efficient&lt;/strong&gt; → No mining required.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decentralized trust&lt;/strong&gt; → Each node defines who it trusts.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilient&lt;/strong&gt; → Safety is guaranteed as long as quorum sets overlap correctly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Takeaway
&lt;/h3&gt;

&lt;p&gt;SCP is Stellar’s way of achieving global agreement without mining or staking. It’s lightweight, secure, and designed for payments. The trick is in quorum design: overlap ensures safety and keeps the network moving forward.&lt;/p&gt;

&lt;p&gt;Next time you hear “consensus,” remember: on Stellar, it’s all about &lt;em&gt;&lt;code&gt;trust&lt;/code&gt; + &lt;code&gt;overlap&lt;/code&gt;&lt;/em&gt;. That’s SCP in a nutshell.&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>algorithms</category>
      <category>blockchain</category>
      <category>architecture</category>
    </item>
    <item>
      <title>The Evolution of the Web: From Static Pages to Decentralized Dreams 🌐</title>
      <dc:creator>Hillary Ombima</dc:creator>
      <pubDate>Wed, 04 Jun 2025 11:21:07 +0000</pubDate>
      <link>https://forem.com/ombima/the-evolution-of-the-web-from-static-pages-to-decentralized-dreams-19l3</link>
      <guid>https://forem.com/ombima/the-evolution-of-the-web-from-static-pages-to-decentralized-dreams-19l3</guid>
      <description>&lt;p&gt;&lt;em&gt;Ever wondered how we went from simple HTML pages to owning digital assets on the blockchain? Let's take a journey through the three eras of the web and explore what makes Web3 so revolutionary.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Cold War Origins
&lt;/h3&gt;

&lt;p&gt;Before diving into the web evolution, here's a fun fact: the internet was born from Cold War paranoia!&lt;/p&gt;

&lt;p&gt;In the 1960s, the U.S. Department of Defense's &lt;strong&gt;ARPA&lt;/strong&gt; created &lt;strong&gt;ARPANET&lt;/strong&gt; — a communication network designed to survive nuclear attacks. The irony? What started as a military defense system became the foundation for cat videos and memes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Did you know?&lt;/strong&gt; The first &lt;strong&gt;ARPANET&lt;/strong&gt; message was sent on October 29, 1969, between UCLA and Stanford. It was supposed to say "LOGIN" but crashed after "LO" — technically making the first internet message failed attempt!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🌍 Web 1.0: The Static Era
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Timeline:&lt;/strong&gt; Early 1990s - 2004&lt;br&gt;
&lt;strong&gt;Core Traits:&lt;/strong&gt; Read-only, static web pages, limited user interaction&lt;/p&gt;

&lt;h4&gt;
  
  
  What Was It Like?
&lt;/h4&gt;

&lt;p&gt;Imagine opening a website and seeing... just text and maybe a few images. No comments, no likes, no sharing buttons. You were essentially reading a digital newspaper that never changed.&lt;/p&gt;

&lt;p&gt;Web 1.0 brought global access to information, allowing anyone to publish content that could be viewed worldwide. It enabled real-time updates, with breaking news reaching millions instantly, and introduced multimedia elements like text, images, and simple audio or video.&lt;/p&gt;

&lt;p&gt;However, it lacked interactivity, users couldn’t comment or engage with the content. Content creation was mostly limited to organizations, leaving everyday users as passive consumers rather than active participants.&lt;/p&gt;

&lt;h3&gt;
  
  
  Web 2.0: The Social Revolution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Timeline:&lt;/strong&gt; ~2004 - Present&lt;br&gt;
&lt;strong&gt;Core Traits:&lt;/strong&gt; User-generated content, interactivity, community-building&lt;/p&gt;

&lt;p&gt;Web2.0 emerged as a response to the static limitations of Web1.0. This new phase of the internet championed interactivity, collaboration, and user participation. It transformed the internet from a one-way information flow into a dynamic space where users could generate and share content freely. &lt;/p&gt;

&lt;p&gt;The rise of blogs, forums, microblogs, and social media platforms like Facebook, Twitter, and TikTok defined this era, allowing people not only to consume content but to actively contribute and engage with global communities.&lt;/p&gt;

&lt;p&gt;However, as user-generated content flourished, so did new challenges. One of the most pressing issues became data ownership—users created content, but platforms retained control over it. This led to increasing concerns about privacy breaches, as personal data became a commodity vulnerable to leaks and exploitation. &lt;/p&gt;

&lt;p&gt;Moreover, filter bubbles began to shape user experience, with algorithms feeding individuals personalized content that often reinforced existing views rather than broadening perspectives. &lt;/p&gt;

&lt;p&gt;On top of that, the creator economy—despite offering new monetization opportunities—was heavily skewed, with platforms taking significant portions of creators' earnings and maintaining dominance over distribution and discovery.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔐 Web 3.0: The Decentralized Future
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Timeline:&lt;/strong&gt; 2015 - Present (Still Emerging)&lt;br&gt;
&lt;strong&gt;Core Traits:&lt;/strong&gt; User-generated content, interactivity, community-building.&lt;/p&gt;

&lt;p&gt;Web3.0 emerged as a bold response to the pitfalls of Web2.0, proposing a radical reimagining of the internet—one where users don’t just consume or create, but truly own their digital lives. At the heart of this shift lies a vision of a more secure, transparent, and user-centric internet that minimizes reliance on centralized authorities like Google and Facebook.&lt;/p&gt;

&lt;p&gt;Rather than entrusting tech giants with personal data, Web3.0 leverages blockchain technology to ensure transparency and security. Central to this are smart contracts, self-executing pieces of code that automate transactions and agreements without the need for intermediaries. &lt;/p&gt;

&lt;p&gt;This foundation has given rise to &lt;strong&gt;Decentralized finance&lt;/strong&gt; (DeFi), enabling financial transactions without banks, and &lt;strong&gt;Non-Fungible tokens&lt;/strong&gt; (NFTs), which allow digital ownership of unique assets. &lt;/p&gt;

&lt;p&gt;The ecosystem further expands with decentralized governance models, such as &lt;strong&gt;DAOs&lt;/strong&gt; (Decentralized Autonomous Organizations), where users participate in decision-making processes, and with distributed storage systems like &lt;strong&gt;IPFS&lt;/strong&gt;, reducing dependency on centralized servers.&lt;/p&gt;

&lt;p&gt;A major milestone in the evolution of Web3.0 was the launch of &lt;a href="https://ethereum.org" rel="noopener noreferrer"&gt;Ethereum&lt;/a&gt; in 2015 by &lt;strong&gt;Vitalik Buterin&lt;/strong&gt; and collaborators. Ethereum provided the first real platform for building decentralized applications (DApps), where logic could be embedded into money through programmable contracts. &lt;/p&gt;

&lt;p&gt;With Ethereum, users could create and interact with apps that didn’t rely on central servers, ushering in a new era of programmable money, trustless execution, and global participation.&lt;/p&gt;

&lt;p&gt;Web3.0 remains in its early stages and presents challenges such as usability, regulation, and accessibility. However, its underlying ethos—empowering individuals through ownership, privacy, and decentralization—continues to gain momentum, pointing toward an internet where control is truly in the hands of its users.&lt;/p&gt;

&lt;h3&gt;
  
  
  📊 The Evolution Summary
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Era&lt;/th&gt;
&lt;th&gt;Key Feature&lt;/th&gt;
&lt;th&gt;You Could...&lt;/th&gt;
&lt;th&gt;You Couldn't...&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Web 1.0&lt;/td&gt;
&lt;td&gt;Read-Only&lt;/td&gt;
&lt;td&gt;Access information&lt;/td&gt;
&lt;td&gt;Interact or create&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web 2.0&lt;/td&gt;
&lt;td&gt;Read-Write&lt;/td&gt;
&lt;td&gt;Create &amp;amp; share content&lt;/td&gt;
&lt;td&gt;Own your data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web 3.0&lt;/td&gt;
&lt;td&gt;Read-Write-Own&lt;/td&gt;
&lt;td&gt;Own digital assets&lt;/td&gt;
&lt;td&gt;Avoid complexity (yet)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  🔗 Connect &amp;amp; Continue Learning
&lt;/h3&gt;

&lt;p&gt;If you enjoyed this deep dive, &lt;em&gt;Let’s connect on&lt;/em&gt; &lt;a href="https://github.com/ombima56" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; / &lt;a href="https://www.linkedin.com/in/hillary-ombima-724430207/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Want to go deeper?
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://ethereum.org/en/whitepaper/" rel="noopener noreferrer"&gt;Ethereum Whitepaper&lt;/a&gt; — The document that started it all&lt;br&gt;
&lt;a href="https://roadmap.sh/web3" rel="noopener noreferrer"&gt;Web3 Developer Roadmap&lt;/a&gt; — If you want to start building&lt;br&gt;
&lt;a href="https://defipulse.com/" rel="noopener noreferrer"&gt;DeFi Pulse&lt;/a&gt; — Track the decentralized finance ecosystem&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What aspect of Web3 are you most curious about? Let me know in the comments, and I might write a deep dive on that topic next! 🚀&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tags: #Web3 #Blockchain #Ethereum #Technology #Internet #Decentralization #Cryptocurrency #Defi #NFTs #Development&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Go's net/http Package: A Comprehensive Guide for Beginners</title>
      <dc:creator>Hillary Ombima</dc:creator>
      <pubDate>Wed, 18 Sep 2024 13:26:39 +0000</pubDate>
      <link>https://forem.com/ombima/mastering-gos-nethttp-package-a-comprehensive-guide-for-beginners-3bc2</link>
      <guid>https://forem.com/ombima/mastering-gos-nethttp-package-a-comprehensive-guide-for-beginners-3bc2</guid>
      <description>&lt;p&gt;The &lt;code&gt;net/http(Hypertext Transfer Protocol)&lt;/code&gt; package in Go is a powerful and versatile tool for building web applications and APIs. Whether you're creating a RESTful API, a simple web server, or a more complex web application, understanding this package is essential. This guide will walk you through the basics of the &lt;code&gt;net/http&lt;/code&gt; package, provide practical examples, and help you build a simple web application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Go's &lt;code&gt;net/http&lt;/code&gt; package is the backbone of web development in Go. It provides the core functionality needed to build HTTP servers and clients, making it a fundamental skill for any Go developer. This guide aims to provide you with a solid foundation in using &lt;code&gt;net/http&lt;/code&gt;, starting from the basics and moving towards more advanced topics. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Understanding the Basics of &lt;code&gt;net/http&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;net/http package&lt;/code&gt; provides the core functionality for HTTP servers and clients in Go. Here's a quick overview of its components: &lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of Key Components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. http.HandleFunc
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Purpose:&lt;/em&gt;&lt;/strong&gt; Registers a handler function for a specific route or URL pattern. &lt;/p&gt;

&lt;h4&gt;
  
  
  How It Works:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This function maps a &lt;code&gt;URL path&lt;/code&gt; to a &lt;code&gt;handler function&lt;/code&gt;. The handler function is responsible for processing requests to that URL path.&lt;/li&gt;
&lt;li&gt;It takes two arguments: &lt;code&gt;the URL pattern&lt;/code&gt; and &lt;code&gt;the handler function&lt;/code&gt;. The URL pattern specifies the route (e.g., &lt;code&gt;/home, /api/data)&lt;/code&gt;, and the handler function defines what happens when a request is made to that route. &lt;/li&gt;
&lt;li&gt;Example: &lt;code&gt;http.HandleFunc("/hello", helloHandler)&lt;/code&gt; registers the &lt;code&gt;helloHandler function&lt;/code&gt; to handle requests to &lt;code&gt;/hello&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The handler function should have the signature &lt;code&gt;func(w 
http.ResponseWriter, r *http.Request)&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;http.HandleFunc is a convenient way to set up route handlers without needing to manually create a multiplexer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. http.ListenAndServe
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; Starts an HTTP server and listens for incoming requests on a specified port. &lt;/p&gt;

&lt;h4&gt;
  
  
  How It Works:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This function takes two arguments: &lt;code&gt;the address to listen on&lt;/code&gt; and &lt;code&gt;a handler to process incoming requests&lt;/code&gt;. If the handler is &lt;code&gt;nil&lt;/code&gt;, the default multiplexer &lt;code&gt;(http.DefaultServeMux)&lt;/code&gt; is used. &lt;/li&gt;
&lt;li&gt;The address is usually in the form of &lt;code&gt;":port"&lt;/code&gt;, where port is the port number the server will listen to &lt;code&gt;(e.g., ":8080")&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;http.ListenAndServe(":8080", nil)&lt;/code&gt; starts an HTTP server on port 8080 and uses the default multiplexer to route requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This function blocks and runs indefinitely, handling requests until the server is stopped. &lt;/li&gt;
&lt;li&gt;Errors returned by &lt;code&gt;http.ListenAndServe (like http.ErrServerClosed)&lt;/code&gt; usually indicate issues with starting the server or running it. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. http.Request and http.ResponseWriter
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Purpose:&lt;/em&gt;&lt;/strong&gt; Represent the HTTP request and response in the handler functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  http.Request Details:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Contains information about the incoming request, such as the HTTP method &lt;code&gt;(GET, POST, etc.), URL, headers, and body&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Provides methods for retrieving URL parameters, query strings, and form data. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example:&lt;/strong&gt; r.Method returns the HTTP method used in the request, and r.URL.Path gives the requested URL path.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. http.ResponseWriter Details:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Used to construct the &lt;code&gt;HTTP response sent back to the client&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Provides methods for setting headers, writing the response body, and setting the HTTP status code. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;w.Write([]byte("Hello World"))&lt;/code&gt; writes the string &lt;code&gt;"Hello World"&lt;/code&gt; to the response body.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Understanding Multiplexers
&lt;/h4&gt;

&lt;p&gt;A multiplexer &lt;code&gt;(mux)&lt;/code&gt; is a fundamental component in handling HTTP requests in Go. It is responsible for routing incoming requests to the appropriate handler functions based on the URL path.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Default Multiplexer &lt;code&gt;(http.DefaultServeMux)&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; Handles routing using the built-in multiplexer provided by the &lt;code&gt;net/http package&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  How It Works:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;http.HandleFunc&lt;/code&gt; registers handlers with the default multiplexer, which is created and managed internally by the Go standard library. &lt;/li&gt;
&lt;li&gt;The default multiplexer routes requests based on the URL path and serves the corresponding registered handler. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is simple and convenient for basic use cases and small applications. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The default multiplexer is used automatically if you pass nil to &lt;br&gt;
&lt;code&gt;http.ListenAndServe&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Custom Multiplexers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Purpose:&lt;/em&gt;&lt;/strong&gt; Allows more advanced routing and &lt;code&gt;middleware&lt;/code&gt; support. &lt;br&gt;
How It Works: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can create custom multiplexers using &lt;code&gt;http.NewServeMux()&lt;/code&gt;. This gives you more control over routing and handler registration. &lt;/li&gt;
&lt;li&gt;Custom &lt;code&gt;multiplexers&lt;/code&gt; are useful for organizing routes and applying &lt;code&gt;middleware&lt;/code&gt; across different parts of your application. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. Example Usage:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Create a new multiplexer:&lt;/em&gt;&lt;/strong&gt; &lt;code&gt;mux := http.NewServeMux()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Register handlers with it:&lt;/em&gt;&lt;/strong&gt; &lt;code&gt;mux.HandleFunc("/home", homeHandler)&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Pass it to http.ListenAndServe:&lt;/em&gt;&lt;/strong&gt; &lt;code&gt;http.ListenAndServe(":8080", mux)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5. Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Custom multiplexers are beneficial for larger applications or when you need specific routing logic that the default multiplexer does not support. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They allow you to set up more complex routing schemes and middleware pipelines. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Handling HTTP Requests and Responses &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A basic handler function might look like this:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Request Method: %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&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;ul&gt;
&lt;li&gt;Creating Simple Handlers

&lt;ul&gt;
&lt;li&gt;Define a handler for the &lt;code&gt;/hello&lt;/code&gt; route:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello, %s!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&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;h2&gt;
  
  
  Step 2: Setting Up Your Go Environment
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Install Go
&lt;/h3&gt;

&lt;p&gt;To get started, you need to have Go installed on your machine.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Visit the &lt;a href="https://golang.org" rel="noopener noreferrer"&gt;Official Go Website&lt;/a&gt; and download the installer for your operating system.
&lt;/h4&gt;
&lt;h4&gt;
  
  
  2. Follow the installation instructions specific to your OS.
&lt;/h4&gt;
&lt;h3&gt;
  
  
  Set Up a Code Editor
&lt;/h3&gt;

&lt;p&gt;Choose a code editor that suits your workflow. Popular options include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio Code &lt;code&gt;(VSCode)&lt;/code&gt;: Install the Go extension from the extensions marketplace.&lt;/li&gt;
&lt;li&gt;GoLand: A feature-rich IDE tailored for Go development.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Verify Installation
&lt;/h3&gt;

&lt;p&gt;Open your terminal and run the following command to verify your Go installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run a Basic HTTP Server (with code example below)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setup and Initialization:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The code starts by importing necessary packages:(eg fmt) for formatted I/O operations and net/http for building the HTTP server.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Defining the Main Function:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;main&lt;/code&gt; function serves as the entry point of the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Understanding the Multiplexer:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; In the Go HTTP server context, the multiplexer is a core component responsible for routing incoming HTTP requests to the appropriate handler functions. It matches the URL path of the request to registered routes and directs the request accordingly.&lt;/li&gt;
&lt;li&gt; The &lt;code&gt;http.HandleFunc&lt;/code&gt; function registers a route with a handler function in the multiplexer. When a request comes in, the multiplexer uses the URL path to find the correct handler.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Registering a Route:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The server sets up a route using http.HandleFunc. This function associates a specific URL path (e.g., &lt;code&gt;/&lt;/code&gt;) with a handler function. &lt;/li&gt;
&lt;li&gt;The handler function processes requests to this route and generates 
responses. In this case, it sends a plain text response back to the client with a welcome message. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Starting the Server:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;http.ListenAndServe&lt;/code&gt; is called to start the HTTP server on a specific port (e.g., port 8080). It initializes the server and starts listening for incoming requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;This function also uses the multiplexer to route requests. It continuously listens for incoming HTTP requests and directs them to the appropriate handlers based on the URL path.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Handling Requests:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;When a request is made to the server, the multiplexer matches the URL path of the request to the registered routes.&lt;/li&gt;
&lt;li&gt;It then invokes the corresponding handler function, which processes the request and sends a response back to the client. &lt;/li&gt;
&lt;li&gt;Here’s an example implementation in code.&lt;/li&gt;
&lt;li&gt;Create a file named &lt;code&gt;main.go&lt;/code&gt; with the following code:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"net/http"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Welcome to net/http guide web page"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListenAndServe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;":8080"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&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;h2&gt;
  
  
  Step 3: Building a Basic Web Server
&lt;/h2&gt;

&lt;p&gt;In this step, you will learn how to build a simple web server that can handle multiple routes. Here’s a detailed explanation of the key concepts involved: &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Setting Up the Server
&lt;/h3&gt;

&lt;p&gt;Concept: You need to set up an HTTP server that listens for incoming network requests. This involves defining how and where the server will listen for requests. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Initialization: Start the server by specifying the port on which it will listen for incoming connections. This port is part of the server's address and allows it to receive network traffic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Execution: The server continues to run, waiting for requests from clients (like web browsers) and handling them according to the routes and handlers you define.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Defining Routes
&lt;/h3&gt;

&lt;p&gt;Concept: Routes are URL paths that your server will respond to. You map these paths to specific functions that process the request and generate a response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Route Mapping:&lt;/strong&gt; Use routing functions to associate specific URL paths (e.g., &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;/about&lt;/code&gt;) with handler functions. Each route corresponds to a different URL pattern that the server recognizes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Route Handlers:&lt;/strong&gt; Each route has an associated handler function that determines how requests to that URL should be processed. These handlers are responsible for generating the appropriate responses. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Creating Handler Functions
&lt;/h3&gt;

&lt;p&gt;Concept: Handler functions define the logic for processing HTTP requests. They determine how to respond to a request based on the URL path and other request details.&lt;br&gt;
&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Request Processing:&lt;/strong&gt; The handler function receives an HTTP request and an HTTP response writer. It processes the request, performs any necessary operations &lt;code&gt;(such as querying a database or computing a result)&lt;/code&gt;, and writes the response back to the client.&lt;/li&gt;
&lt;li&gt;Generating Responses: The function uses the response writer to send data (like HTML or plain text) back to the client. This is where you define what content the user will see in their web browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. Sending Responses
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Concept:&lt;/strong&gt; After processing a request, your server must send a response back to the client. This response can include various types of content, such as plain text, HTML, or JSON.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Response Writing:&lt;/strong&gt; Use the response writer to format and send the content of the response. This might include setting the HTTP status code (e.g., 200 for success) and writing the body of the response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Types:&lt;/strong&gt; The content can be as simple as a welcome message or as complex as dynamically generated HTML or JSON data.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Detailed Overview of a Simple HTTP Server with Multiple Routes
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Server Setup:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Initialize the server and specify the port to listen for incoming connections. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; The server runs indefinitely, handling requests as they come in.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  2. Route Definition:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Define how the server should respond to different URL paths. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; Map each URL path to a specific handler function using route registration methods.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  3. Handler Functions:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; Process incoming requests and generate responses. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Logic:&lt;/strong&gt; Each function handles a specific route, processes the request data, and writes a response to the client.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. Response Handling:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Send a response back to the client with appropriate content. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; Write data to the response writer, which sends it to the client's web browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By understanding these components and their interactions, you can build a basic web server that handles multiple routes, processes requests, and sends responses, laying the groundwork for more complex web applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implement a Simple HTTP Server

&lt;ul&gt;
&lt;li&gt;Example server with multiple routes:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; 
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; 
   &lt;span class="s"&gt;"fmt"&lt;/span&gt; 
   &lt;span class="s"&gt;"net/http"&lt;/span&gt; 
&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
   &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;homeHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
   &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aboutHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
   &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListenAndServe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;":8080"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;homeHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Welcome to the Home Page!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;aboutHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"About net/http"&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;ul&gt;
&lt;li&gt;
&lt;p&gt;Define Routes and Handlers&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add more routes and handlers as needed for your application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test Your Server&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a web browser or tools like curl to test different routes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4: Handling Different HTTP Methods
&lt;/h2&gt;

&lt;p&gt;Different HTTP methods &lt;code&gt;(GET, POST, PUT, DELETE)&lt;/code&gt; are essential for &lt;code&gt;RESTful APIs&lt;/code&gt; and web applications.&lt;/p&gt;
&lt;h3&gt;
  
  
  Understanding HTTP Methods for Web Development
&lt;/h3&gt;

&lt;p&gt;HTTP methods are fundamental to how web applications and APIs interact with clients. Each method serves a specific purpose in handling requests and performing operations. Here’s a deeper dive into the most commonly used HTTP methods and how they are typically handled in web applications:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. GET Method
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval of Data:&lt;/strong&gt; The GET method is used to request data from a specified resource. It is designed to retrieve information without making any modifications to the data on the server. 
Characteristics: &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotent:&lt;/strong&gt; Multiple identical GET requests should have the same effect as a single request. They should not change any server state. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe:&lt;/strong&gt; It should not cause any side effects on the server. The operation is read-only.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Usage:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fetching Data:&lt;/strong&gt; When a user requests a webpage or an API endpoint that provides information (e.g., &lt;code&gt;retrieving a list of users or displaying a product's details&lt;/code&gt;), a &lt;code&gt;GET&lt;/code&gt; request is typically used.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  2. POST Method
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Submitting Data:&lt;/strong&gt; The &lt;code&gt;POST method&lt;/code&gt; is used to submit data to be processed to a specified resource. This often involves creating or updating data on the server. &lt;br&gt;
Characteristics: &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non-idempotent:&lt;/strong&gt; Submitting the same data multiple times can result in different outcomes, such as creating multiple records or processing the same transaction multiple times. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Transmission:&lt;/strong&gt; It often involves sending data in the request body, which is processed by the server to create or update a resource.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Form Submissions:&lt;/strong&gt; When users submit forms on a website (like signing up or posting a comment), the server uses POST requests to process and store the data. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  3. PUT Method
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Updating Data:&lt;/strong&gt; The &lt;code&gt;PUT method&lt;/code&gt; is used to update a resource with new data. It can also be used to create a resource if it doesn’t already exist. &lt;br&gt;
Characteristics: &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Idempotent:&lt;/strong&gt; Multiple identical PUT requests should result in the same outcome as a single request. It replaces the resource's current state with the new data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Complete Replacement:&lt;/strong&gt; Typically, PUT requests replace the entire resource with the new data provided. &lt;br&gt;
Usage: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resource Updates:&lt;/strong&gt; When updating a resource (like editing a user's profile information or changing a product's details), the server uses PUT requests to apply these updates.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. DELETE Method
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Removing Data:&lt;/strong&gt; The DELETE method is used to remove a specified resource from the server. 
Characteristics: &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotent:&lt;/strong&gt; Multiple identical &lt;code&gt;DELETE&lt;/code&gt; requests should have the same effect as a single request. Once a resource is deleted, further DELETE requests for the same resource should have no additional effect. 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resource Deletion:&lt;/strong&gt; It instructs the server to delete the specified resource. #### Usage: &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Removing Items:&lt;/strong&gt; When deleting a resource (like removing a user account or deleting a product from an inventory), the server uses DELETE requests to carry out this action. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Handling GET and POST Requests
&lt;/h3&gt;

&lt;p&gt;In a web application, handling GET and POST requests involves defining how your server should process these requests and generate responses. Here's a breakdown of how these methods are typically handled:&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Handling GET Requests:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Define Endpoints: Set up routes that respond to GET requests by fetching and returning data from the server. &lt;/li&gt;
&lt;li&gt;Retrieve Data: Access the requested resource or query the database to retrieve the necessary information. &lt;/li&gt;
&lt;li&gt;Respond to Client: Send the retrieved data back to the client in the appropriate format (e.g., HTML, JSON).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  2. Handling POST Requests:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Define Endpoints: Set up routes that respond to POST requests by accepting data submitted by the client. &lt;/li&gt;
&lt;li&gt;Process Data: Parse and validate the data from the request body. Perform the necessary operations (e.g., saving data to a database). &lt;/li&gt;
&lt;li&gt;Respond to Client: Provide a response indicating the result of the operation (e.g., success message, newly created resource details). 
By understanding and correctly implementing these HTTP methods, you can build robust web applications and APIs that effectively handle various types of interactions with clients. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of GET and POST in code implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handlePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodPost&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="c"&gt;// Handle POST request &lt;/span&gt;
   &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"POST request received"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="c"&gt;// GET request handler &lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handleGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodGet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="c"&gt;// Handle GET request &lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"GET request received"&lt;/span&gt;&lt;span class="p"&gt;)&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;ul&gt;
&lt;li&gt;Implementing Handlers for Each Method

&lt;ul&gt;
&lt;li&gt;Example of handling a PUT request:
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handlePut&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodPut&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="c"&gt;// Handle PUT request &lt;/span&gt;
   &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"PUT request received"&lt;/span&gt;&lt;span class="p"&gt;)&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;h2&gt;
  
  
  Step 5: Working with Request Parameters
&lt;/h2&gt;

&lt;p&gt;Handling request parameters is crucial for building dynamic web applications, as it allows your server to interact with user input and customize responses based on that input. Here’s a detailed explanation of how query parameters work and how they are managed in web applications:&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Query Parameters
&lt;/h3&gt;

&lt;p&gt;Query Parameters: These are key-value pairs included in the URL of a request. They are used to pass additional data to the server in a flexible and user-friendly way.&lt;br&gt;
Structure: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; URL Format: Query parameters are appended to the end of the URL after a question mark &lt;code&gt;(?)&lt;/code&gt;. Multiple parameters are separated by an ampersand &lt;code&gt;(&amp;amp;)&lt;/code&gt;. 
This is an  example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://example.com/page?key1=value1&amp;amp;key2=value2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Keys and Values:&lt;/strong&gt; Each parameter consists of a key and a value, separated by an equals sign &lt;code&gt;(=)&lt;/code&gt;. The key is the name of the parameter, and the value is the data associated with that key.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Query Parameters Are Handled
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Extraction:&lt;/strong&gt; When a client makes a request to a server, the server can extract query parameters from the URL to customize the response based on the provided data. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decoding:&lt;/strong&gt; Query parameters are usually URL-encoded, meaning special characters are replaced with percent-encoded values (e.g., spaces become %20). The server needs to decode these parameters to interpret them correctly. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validation:&lt;/strong&gt; Extracted query parameters should be validated to ensure they meet expected formats and constraints. This helps in preventing issues such as SQL injection or malformed data from causing errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; Once validated, query parameters can be used to: 

&lt;ul&gt;
&lt;li&gt;Filter data (e.g., &lt;code&gt;displaying search results based on a keyword&lt;/code&gt;). &lt;/li&gt;
&lt;li&gt;Customize content (e.g., &lt;code&gt;displaying user-specific information&lt;/code&gt;). &lt;/li&gt;
&lt;li&gt;Control behavior (e.g., &lt;code&gt;pagination in a list of items&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example Workflow
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client Request:&lt;/strong&gt; A user submits a form or clicks a link that includes query parameters in the URL. For example, a search for "Go programming" might result in a URL like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;http://example.com/search?q&lt;span class="o"&gt;=&lt;/span&gt;Go+programming&amp;amp;sort&lt;span class="o"&gt;=&lt;/span&gt;latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  1. Server Handling:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The server receives the request and extracts the query parameters from the URL. &lt;/li&gt;
&lt;li&gt;&lt;p&gt;It decodes the parameters and validates them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Based on the parameters, the server performs the necessary operations, such as querying a database for results or generating a specific response.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally, it sends back a response tailored to the query parameters.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Response:&lt;/strong&gt; The server's response includes the requested data or performs the action based on the provided parameters. For instance, it might display search results ordered by the latest entries if the sort=latest parameter was provided. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Handling Query Parameters in Practice
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessing Parameters:&lt;/strong&gt; In many web frameworks, you can access query parameters through request objects. They provide methods or properties to retrieve parameter values. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error Handling:&lt;/strong&gt; Handle cases where parameters might be missing or invalid by providing default values or error messages. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security Considerations:&lt;/strong&gt; Be cautious with user input in query parameters. Always validate and sanitize input to avoid security vulnerabilities. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve query parameters from the URL example with code:
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;searchHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"q"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="n"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"sort"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"No search query provided."&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Searching for: %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" | Sorted by: %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&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;h4&gt;
  
  
  How to Test:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start the Server:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Run the Go program to start the server on &lt;code&gt;http://localhost:8080&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Test Different URLs:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Access &lt;code&gt;http://localhost:8080/&lt;/code&gt; to see the welcome message. &lt;/li&gt;
&lt;li&gt;Access &lt;code&gt;http://localhost:8080/search?q=golang&amp;amp;sort=date&lt;/code&gt; to see a message including the search query and sorting order.&lt;/li&gt;
&lt;li&gt;Access &lt;code&gt;http://localhost:8080/search?q=golang&lt;/code&gt; to see a message with only the search query.&lt;/li&gt;
&lt;li&gt;Access &lt;a href="http://localhost:8080/search%60" rel="noopener noreferrer"&gt;http://localhost:8080/search`&lt;/a&gt; to see the message indicating that no search query was provided.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Form Data
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Handling Form Submissions
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Overview:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handling form submissions involves processing data sent from an HTML form to the server.&lt;/li&gt;
&lt;li&gt;This data is typically sent using the POST method and can be accessed and processed in the handler function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Explanation:
&lt;/h4&gt;

&lt;h4&gt;
  
  
  1. Form Submission Method:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When a form is submitted using the POST method, the data is included in the body of the request.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Parsing Form Data:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The r.ParseForm() method is used to parse the form data.
This method populates r.Form with the submitted form values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Retrieving Form Values:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;r.FormValue("name") retrieves the value of the form field named "name". It returns an empty string if the field is not present.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Sending a Response:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The response is generated based on the submitted form data. In this case, it simply acknowledges the submitted name.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example Usage:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;HTML Form Submission:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fad309l77xt99ga8cv13m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fad309l77xt99ga8cv13m.png" alt="HTML Form Code Snippet" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Handler Processing:&lt;/strong&gt; The handler reads the form data and responds with a message indicating the submitted name.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  URL Path Parameters
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Overview:&lt;/strong&gt; URL path parameters are dynamic segments in the URL path used to identify specific resources. They are extracted directly from the URL path.&lt;/p&gt;

&lt;h4&gt;
  
  
  Explanation:
&lt;/h4&gt;

&lt;h4&gt;
  
  
  1. Extracting Path Parameters:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Path parameters are part of the URL itself. For example, in the URL /items/123, 123 is a path parameter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Processing Path Parameters:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;To extract the parameter, you can use string manipulation methods like strings.TrimPrefix to remove the fixed part of the path (/items/ in this case) and retrieve the dynamic part (123).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Generating a Response:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The handler uses the extracted path parameter to generate a response. In this case, it simply displays the extracted item ID.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example Usage:
&lt;/h4&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Request URL:&lt;/strong&gt; Accessing &lt;a href="http://localhost:8080/items/123" rel="noopener noreferrer"&gt;http://localhost:8080/items/123&lt;/a&gt; would extract 123 as the item ID from the URL path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Handler Processing:&lt;/strong&gt; The handler reads the item ID from the path and responds with a message that includes the item ID.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle form submissions example:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnmkem9fz8r8d2nzuqgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnmkem9fz8r8d2nzuqgm.png" alt="Getting item by ID" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; URL Path Parameters

&lt;ul&gt;
&lt;li&gt;Extract parameters from the URL path:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxeo3hnf2hybthip92521.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxeo3hnf2hybthip92521.png" alt="URL path parameter" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Creating a RESTful API
&lt;/h2&gt;

&lt;p&gt;Creating a RESTful API involves several important steps, from defining the endpoints to handling the data sent and received. Here's a detailed explanation of the key elements involved:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Define API Endpoints
&lt;/h3&gt;

&lt;p&gt;Endpoints are specific URLs through which clients interact with the API. They represent various resources and operations that the API provides.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Endpoints Overview:

&lt;ul&gt;
&lt;li&gt;Resource Representation: Each endpoint typically corresponds to a resource or a collection of resources. For instance, if you’re building an API for managing books, you might have endpoints for retrieving a list of books, getting details of a single book, creating a new book, updating an existing book, and deleting a book.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;HTTP Methods:&lt;/strong&gt; Endpoints use HTTP methods to define operations on resources: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET:&lt;/strong&gt; Retrieve information from the server. For example, GET 
/books retrieves a list of books.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST:&lt;/strong&gt; Create a new resource on the server. For example, POST 
/books adds a new book.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT:&lt;/strong&gt; Update an existing resource. For example, PUT /books/123 updates the book with ID 123.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE:&lt;/strong&gt; Remove a resource from the server. For example, DELETE /books/123 deletes the book with ID 123.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Designing Endpoints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Plural Nouns:&lt;/strong&gt; Typically, use plural nouns for resource names to represent collections. For example, /books for a collection of books and /books/{id} for a single book.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Hierarchy:&lt;/strong&gt; Reflect relationships between resources in your endpoint structure. For example, if books belong to authors, you might have endpoints like /authors/{id}/books to get all books by a specific author.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Maintain a consistent naming convention and endpoint structure throughout the API to ensure predictability and ease of use.
### 2. Handle JSON Data
JSON (JavaScript Object Notation) is the most commonly used data format for APIs. It’s lightweight, easy to read, and simple to parse.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Handling JSON Requests:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parse JSON Data:&lt;/strong&gt; When a client sends data to the server, it often comes in JSON format. The server needs to parse this JSON data to extract the information needed to process the request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Validation:&lt;/strong&gt; Ensure that the incoming JSON data adheres to the expected format and contains all necessary fields. Validate the data to prevent errors and ensure consistency.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Handling JSON Responses:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Format Responses:&lt;/strong&gt; When responding to client requests, format the response data as JSON. This allows the client to easily parse and use the data.&lt;/li&gt;
&lt;li&gt;Include Status Codes: Use HTTP status codes to indicate the result of the request. For example, return a 200 OK status for successful requests, 404 Not Found for non-existent resources, and 500 Internal Server Error for unexpected issues.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Example Workflow
&lt;/h3&gt;

&lt;p&gt;Here’s a simplified workflow of how a RESTful API handles a typical request and response cycle:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Client Request:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The client sends an HTTP request to the API endpoint. For example, a GET request to /books/123 to retrieve details of a specific book.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Server Processing:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Extracting Data:&lt;/strong&gt; The server extracts information from the request URL and any query parameters or request body.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performing Operations:&lt;/strong&gt; The server performs the necessary operations, such as querying the database or performing business logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Server Response:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Formatting Data:&lt;/strong&gt; The server formats the response data as JSON. &lt;/li&gt;
&lt;li&gt;Sending Response: The server sends the JSON data back to the client along with an appropriate HTTP status code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Client Handling:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The client receives the JSON response, processes the data, and updates the user interface or performs other actions based on the response.

&lt;ul&gt;
&lt;li&gt;Define your API endpoints:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69adydn2zmrnssuuvsvr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69adydn2zmrnssuuvsvr.png" alt="Defining api" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle JSON Requests and Responses

&lt;ul&gt;
&lt;li&gt;Parse JSON request body: &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnwpxgxd58ui9l1naalf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnwpxgxd58ui9l1naalf.png" alt="Parse JSON request" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Implement CRUD Operations 

&lt;ul&gt;
&lt;li&gt;Create, Read, Update, Delete operations for managing resources.
To implement the CRUD (Create, Read, Update, Delete) operations in your Go application using the net/http package, you typically define these operations in your handlers. These handlers will be associated with specific routes to manage your resources (e.g., books, users).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Create Operation (POST)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Where to Implement:&lt;/strong&gt; In a handler function that is associated with a POST request to a specific route.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Example:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02qjc57tvs9xsz3gg90k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02qjc57tvs9xsz3gg90k.png" alt="To POST" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.  Update Operation (PUT)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Where to Implement: In a handler function that is associated with a PUT request to update an existing resource.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example in code:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4ishhje6mcysdrqbs33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4ishhje6mcysdrqbs33.png" alt="Image for GET item" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Delete Operation (DELETE)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Where to Implement: In a handler function that is associated with a DELETE request to remove a resource.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example in code:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zoz3s9683x1k0ugydxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zoz3s9683x1k0ugydxb.png" alt="Image description for delete item" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to Add These Handlers
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Routing Configuration:
&lt;/h4&gt;

&lt;p&gt;Add these handler functions to your routing configuration in the main.go or a separate file where you define your routes. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fckx6liiqzqfdv67kdtk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fckx6liiqzqfdv67kdtk2.png" alt="Image description for routing handlers" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Organizing Your Code
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a Separate File:&lt;/strong&gt; Consider creating a file like handlers.go to keep your handler functions organized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refactor for Reusability:&lt;/strong&gt; If your CRUD operations involve a lot of common code (e.g., error handling, database connections), you can refactor them into helper functions or middleware.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By implementing the CRUD operations in this manner, you'll build a fully functional API that handles creating, reading, updating, and deleting resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Error Handling and Logging
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Error Handling
&lt;/h3&gt;

&lt;p&gt;Error handling involves managing different kinds of issues that might arise during the execution of your application. In the context of HTTP servers, this usually involves:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Detecting Errors:&lt;/strong&gt; Identifying when something goes wrong, such as invalid input, missing resources, or server issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Returning Error Responses:&lt;/strong&gt; Sending appropriate HTTP status codes and messages to the client to indicate what went wrong. This helps the client understand the nature of the problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Providing User-Friendly Messages:&lt;/strong&gt; Offering clear and helpful messages to users so they know what actions to take.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Custom Error Handlers
&lt;/h3&gt;

&lt;p&gt;A custom error handler is a function that processes errors and generates appropriate responses. Implementing a custom error handler involves:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Defining an Error Handler Function:&lt;/strong&gt; This function is responsible for generating error responses in a consistent format. It takes the http.ResponseWriter and http.Request as parameters, processes the error, and writes a response to the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Using Middleware:&lt;/strong&gt; In more complex applications, you might use middleware to centralize error handling. Middleware functions wrap around your route handlers and handle errors that occur during request processing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Logging Errors: Logging errors is important for debugging and understanding application issues. It involves recording detailed information about the error (like stack traces, request details, etc.) to a log file or monitoring system.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example of Implementing Custom Error Handlers
&lt;/h4&gt;

&lt;p&gt;To implement a custom error handler, you need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Function:&lt;/strong&gt; Define a function that generates a structured error response. This function might format the error message, set the appropriate HTTP status code, and log the error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrate the Error Handler:&lt;/strong&gt; Use this function in your route handlers to handle and respond to errors.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s a high-level explanation of how you would implement this:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Define an Error Handler Function:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This function takes the http.ResponseWriter, http.Request, and an error message or status code.&lt;/li&gt;
&lt;li&gt;It formats the error message, sets the response status code, and writes the response.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Modify Route Handlers:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In your route handlers, use the error handler function when an error occurs. ○ Instead of directly writing the error response in the handler, call the custom error handler function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example Overview
&lt;/h4&gt;

&lt;p&gt;Suppose you want to handle errors for invalid item IDs and bad request formats. You could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an Error Handler Function:&lt;/strong&gt; Define a function to handle errors, which formats the error message and sets the HTTP status code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use the Error Handler in Route Handlers:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your route handlers, if an error condition is met (e.g., invalid ID or decoding failure), call the custom error handler function.&lt;/li&gt;
&lt;li&gt;Ensure that all error responses are consistent and provide useful information to the client.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Benefits of Custom Error Handlers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Consistency:&lt;/strong&gt; Ensures that error responses are uniform across the application, making it easier for clients to handle errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability:&lt;/strong&gt; Simplifies updating error handling logic in one place, rather than modifying individual route handlers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging:&lt;/strong&gt; Provides detailed logging and error messages that are crucial for diagnosing and fixing issues in your application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Implementing Custom Error Handlers
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt; Create a custom error handler:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gt13u87z0vxf523mwyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gt13u87z0vxf523mwyo.png" alt="Image description for Custom Error Handler" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Logging Requests and Errors
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Log request details:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxllf92n6ede0m2wmwxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxllf92n6ede0m2wmwxg.png" alt="Image description for logging custom Error" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Testing Your HTTP Server
&lt;/h2&gt;

&lt;p&gt;Testing your HTTP server involves creating tests that verify whether your server's routes, handlers, and functionalities work correctly. There are different types of tests you might write, but for HTTP servers, unit tests and integration tests are most common.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Writing Unit Tests for Handlers
&lt;/h3&gt;

&lt;p&gt;Unit tests for HTTP handlers focus on testing individual route handlers in isolation. They check if the handlers process requests correctly and generate the expected responses. Here's a deeper dive into writing unit tests for handlers using Go's httptest package:&lt;/p&gt;

&lt;h4&gt;
  
  
  a.  What is httptest?
&lt;/h4&gt;

&lt;p&gt;httptest is a package in Go that provides utilities for testing HTTP handlers. It allows you to create mock HTTP requests and responses and to test how your handlers handle these requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  b. Key Components
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;httptest.NewRequest: Creates a new HTTP request for testing purposes. You can set the URL, method, and body of the request.&lt;/li&gt;
&lt;li&gt; httptest.NewRecorder: Records the HTTP response generated by a handler. It captures the status code, headers, and body so you can assert on them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  c. Writing a Test
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Test Function:&lt;/strong&gt; Define a function with a name starting with Test and accepting a *testing.T parameter. This function will contain your test logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set Up the Request:&lt;/strong&gt; Use httptest.NewRequest to create a request that simulates a real HTTP request. This includes specifying the method (e.g., GET, POST), URL, and any necessary request body or headers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record the Response:&lt;/strong&gt; Use httptest.NewRecorder to create a response recorder that will capture the output of your handler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invoke the Handler:&lt;/strong&gt; Call your handler function with the request and response recorder. This simulates the request being processed by your server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the Results:&lt;/strong&gt; Assert that the recorded response matches your expectations. This includes checking the status code, response headers, and body content.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  d. Example of a Unit Test
&lt;/h4&gt;

&lt;p&gt;For an HTTP handler that processes GET requests to return a list of items, you would:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Set Up the Test Request:&lt;/strong&gt; Create a mock GET request to the appropriate URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record the Response:&lt;/strong&gt; Initialize a response recorder to capture the handler's output.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invoke the Handler:&lt;/strong&gt; Pass the mock request and response recorder to your handler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assert the Response:&lt;/strong&gt; Check that the response status code and body match your expectations.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example Overview
&lt;/h4&gt;

&lt;p&gt;Assume you have a handler getItemsHandler that should return a list of items in JSON format:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Request:&lt;/strong&gt; You simulate a GET request to the /items endpoint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record the Response:&lt;/strong&gt; You capture the response using a recorder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invoke the Handler:&lt;/strong&gt; Call getItemsHandler with the mock request and recorder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assert the Results:&lt;/strong&gt; Verify that the response status code is 200 OK, and the response body contains the expected JSON data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Benefits of Testing
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reliability:&lt;/strong&gt; Ensures that your handlers work as intended and handle edge cases correctly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Catch Bugs Early:&lt;/strong&gt; Identifies issues during development before they affect users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refactoring Safety:&lt;/strong&gt; Provides confidence that changes to your code do not introduce new bugs. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation:&lt;/strong&gt; Tests can serve as documentation for how your handlers are expected to behave.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Best Practices
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write Testable Code:&lt;/strong&gt; Ensure that your handlers are modular and testable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Table-Driven Tests:&lt;/strong&gt; Structure tests in tables for different input scenarios and expected outcomes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolate Tests:&lt;/strong&gt; Each test should focus on a single aspect of the handler's behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean Up:&lt;/strong&gt; Ensure that your tests do not rely on external systems or mutable state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Testing your HTTP server thoroughly helps in maintaining a robust application and ensures that your server's functionalities work as expected.&lt;/p&gt;

&lt;p&gt;Example on how to write Unit Tests for Handlers using httptest:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc38qjbuqt0gk6tsngley.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc38qjbuqt0gk6tsngley.png" alt="Image description for testing Handler" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the httptest Package

&lt;ul&gt;
&lt;li&gt;Utilize httptest to create mock requests and responses for testing.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By now, you should have a solid understanding of Go's net/http package and how to use it to build web applications and APIs. Whether you're creating a simple web server or a complex API, the concepts covered in this guide will serve as a foundation for your Go web development journey.&lt;/p&gt;

&lt;p&gt;For a complete implementation and additional examples, you can explore the full code in the GitHub repository: &lt;a href="https://github.com/ombima56/net-http-guide.git" rel="noopener noreferrer"&gt;net-http-guide&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;p&gt;Feel free to clone the repository, experiment with the code, and adapt it for your needs. If you have any questions or feedback, don’t hesitate to reach out!&lt;/p&gt;

&lt;p&gt;Follow me on GitHub: &lt;a href="https://github.com/ombima56" rel="noopener noreferrer"&gt;https://github.com/ombima56&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
