<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayush Soni</title>
    <description>The latest articles on DEV Community by Ayush Soni (@ayushsoni1010).</description>
    <link>https://dev.to/ayushsoni1010</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%2F630443%2F6cdc811b-86a0-46bc-adf7-7b7ad3644ae3.jpg</url>
      <title>DEV Community: Ayush Soni</title>
      <link>https://dev.to/ayushsoni1010</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayushsoni1010"/>
    <language>en</language>
    <item>
      <title>Git Together: Pro Tips for Commits and Branches</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Mon, 22 Jul 2024 11:29:27 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/git-together-pro-tips-for-commits-and-branches-29l0</link>
      <guid>https://dev.to/ayushsoni1010/git-together-pro-tips-for-commits-and-branches-29l0</guid>
      <description>&lt;p&gt;Hey everyone, In today's blog, I want to share some best practices for using Git more effectively. You know Git, right? Yes, the Git that you’re already familiar with and that amazing tool which makes our coding journey smooth. Git is like your trusty sidekick in coding, making project collaboration a breeze.&lt;/p&gt;

&lt;p&gt;When a developer looks back at commits from 6–8 months ago, it’s often hard to remember why a particular commit was made. This usually happens because the commit message wasn’t clear. Following commit message standards is key. By adopting these practices, your commits will be clear and easy to understand for you or anyone reviewing them later.&lt;/p&gt;

&lt;p&gt;A well-written Git commit message is the best way to convey the context of changes to other developers. Also, the team should agree on a commit message convention that clearly specifies the version control history of the project/product they are building.&lt;/p&gt;

&lt;p&gt;👀 &lt;strong&gt;Before you dive in:&lt;br&gt;
-&lt;/strong&gt; I have organised each sub-section on &lt;strong&gt;Branch Naming Conventions&lt;/strong&gt; and &lt;strong&gt;Commit Message Conventions&lt;/strong&gt; into basic, intermediate and advanced rules.&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Feel free to follow the rules up to whichever level suits your needs, but I recommend sticking to at least the &lt;strong&gt;intermediate level&lt;/strong&gt; for the best results.&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; The content here is adapted and organised from various resources, which you’ll find listed in the &lt;strong&gt;Reference&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;Do you often create branches without knowing why, struggle to understand your own commits or find yourself digging through file changes to make sense of a commit? If that sounds familiar, don't worry. I've got some easy-to-follow tips to help you out.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why should I follow the standards?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Clarity and Understanding:&lt;/strong&gt; Ever looked at a commit from months ago and wondered, “&lt;strong&gt;What was I thinking?&lt;/strong&gt;”. Clear commit messages make it easy to understand the purpose of changes, even after a long time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration and Teamwork:&lt;/strong&gt; Well-written messages help everyone on the team stay on the same page and work together more effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Navigation and Maintenance:&lt;/strong&gt; Following standards makes navigating and maintaining the codebase straightforward and less of a headache.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation and Knowledge Transfer:&lt;/strong&gt; Good commit messages act like mini-documents, helping new team members quickly get up to speed on the project history.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Project Quality:&lt;/strong&gt; Consistent practices improve the overall quality and reliability of the project, making it stronger and more resilient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Changelogs:&lt;/strong&gt; By sticking to standards, you can generate automated changelogs, making release management a breeze.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimizing CI/CD:&lt;/strong&gt; Clear commit messages can enhance your continuous integration and continuous deployment processes, providing essential context for automated tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging and Issue Resolution:&lt;/strong&gt; When problems arise, standardised messages help quickly identify the cause, making debugging and issue resolution faster and easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accountability:&lt;/strong&gt; Clear messages document who made specific changes and why, adding. a layer of accountability to the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency Across Projects:&lt;/strong&gt; Adhering to commit message standards ensures consistency across different projects, making it easier for the developers to switch between projects and understand their histories.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Branch Naming Conventions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basics
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Descriptive Names:&lt;/strong&gt; A well-named branch gives immediate context for its purpose. Instead of generic names, choose clarity.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `feature/login`
- `bugfix/navbar-overflow`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Hyphens:&lt;/strong&gt; Use hyphens (kebab case) to separate words in branch names for better readability.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `bugfix/fix-login-issue` is more readable than `bugfix/fixLoginIssue` or `bugfix/fix_login_issue`.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Alphanumeric Lowercase Characters:&lt;/strong&gt; Stick to alphanumeric lowercase characters (a-z,0-9) and hyphens. Avoid punctuation, spaces, underscores, or special characters whenever possible.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Avoid Unnecessary Hyphens:&lt;/strong&gt; Don’t use unnecessary hyphens like subsequent or trailing hyphens.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `feat/new—login—` is a bad practice.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Short and Effective:&lt;/strong&gt; Keep branch names simple. They should be descriptive yet concise enough to convey the goal at a glance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Prefix or Type
&lt;/h3&gt;

&lt;p&gt;Prefixing branches helps to organise them according to their purpose. This not only improves clarity but also aids in automating workflows.&lt;/p&gt;

&lt;p&gt;Here are some common branch type prefixes and their usage:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;feature/&lt;/strong&gt;: For developing new features. 
For example: 

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;feature/new-dashboard&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;feature/user-profile-page&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;feature/new-feature&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;bugfix/&lt;/strong&gt;: For fixing bugs in the code. Often associated with an issue. Examples: &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `bugfix/login-error`
- `bugfix/incorrect-calculation`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;hotfix/&lt;/strong&gt;: For addressing critical bugs in production. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `hotfix/memory-leak`
- `hotfix/urgent-security-patch`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;release/&lt;/strong&gt;: For preparing a new release, typically used for final touches and revisions. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `release/version-1.0.0`
- `release/2.1.0-final`
- `release/version-1.0.0`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;docs/&lt;/strong&gt;: For writing, modifying, or correcting documentation. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `docs/update-api-docs`
- `docs/installation-guide`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;chore/&lt;/strong&gt;: For routine tasks and maintenance that don’t affect the code’s functionality, like updating dependencies or building scripts. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `chore/dependency-update`
- `chore/refactor-build-scripts`
- `chore/update-dependencies`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;test/&lt;/strong&gt;: For adding or updating tests. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `test/add-unit-tests`
- `test/fix-integration-tests`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;style/&lt;/strong&gt;: For changes that do not affect the code's functionality but improve formatting, like code style or linting fixes.&lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `style/code-cleanup`
- `style/fix-indentation`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;perf/&lt;/strong&gt;: For performance improvements.&lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `perf/optimize-loading-time`
- `perf/reduce-memory-usage`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;revert/&lt;/strong&gt;: For reverting previous changes.&lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `revert/feature-branch-name`
- `revert/hotfix-issue-123`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;refactor/&lt;/strong&gt;: For code refactoring that doesn’t change functionality but improves code structure or readability.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `refactor/optimize-helpers`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;experiment/:&lt;/strong&gt; For experimental features or changes that are still in the testing phase.&lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `experiment/new-algorithm-test`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;build/&lt;/strong&gt;: For changes to the build process or configuration.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `build/update-webpack-config`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Including Ticket Numbers
&lt;/h3&gt;

&lt;p&gt;If your project uses an issue tracking system like Jira, GitHub Issues, or another tool, include the issue token in the branch name. This practice makes it easy to track and reference related tasks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;feature/PROJ-123-footer-links&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Additional Context
&lt;/h3&gt;

&lt;p&gt;Using a consistent branch naming convention helps everyone on the team understand the purpose of each branch at a glance and streamlines the development workflow. It also makes it easier to integrate with CI/CD pipelines and automated tools, as well as to maintain a clean and organized repository.&lt;/p&gt;


&lt;h2&gt;
  
  
  Commit Messages Convention
&lt;/h2&gt;

&lt;p&gt;As an open-source contributor/maintainer who experienced these good practices at a startup, squash feature branches onto &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;main&lt;/code&gt; and write a standardized commit message while doing so. Writing clear and effective commit messages is crucial for maintaining a well-documented codebase. Here’s how you can structure your commit messages for maximum clarity and consistency:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;type&amp;gt;&lt;/span&gt;[optional scope]: &lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;

[optional body]

[optional footer]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Message Subject
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Imperative Mood:&lt;/strong&gt; Write commit messages in the imperative mood. Start with a verb to indicate what the commit does.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Use `fix: correct typo in homepage` instead of `fix: Corrected typo in homepage`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Short and Standardized:&lt;/strong&gt; Keep the subject line within 50 characters to ensure readability in various Git tools, like when using &lt;code&gt;git log --oneline&lt;/code&gt;. Avoid trailing periods and unnecessary words or symbols.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Capitalize the Description:&lt;/strong&gt; Start the subject line with a capital letter.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Type and Message Body
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type Prefix:&lt;/strong&gt; Use a type prefix in the subject line to represent the nature of the changes included in the commit. The commit type should include:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;feat:&lt;/code&gt; Summarizes a feature in the codebase.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fix:&lt;/code&gt; Addresses a fix to the codebase.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build&lt;/code&gt;, &lt;code&gt;chore&lt;/code&gt;, &lt;code&gt;ci&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt; and &lt;code&gt;refactor&lt;/code&gt; are other examples.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Scope:&lt;/strong&gt; Optionally add a scope  to the commit’s type to provide additional context. Enclose the scope in parentheses.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `feat(auth): add OAuth support`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Message Body:&lt;/strong&gt; Add detailed explanations in the commit body. Leave a blank line after the subject line to separate it from the body.&lt;/p&gt;


💡 **Wrap the body at 72 characters:** Use multiple lines of body text, ensuring each line does not exceed 72 characters limit.

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Footer and Extended Message Body
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Footer:&lt;/strong&gt; Use the footer to convey additional details regarding the commit like such as &lt;code&gt;Reviewed-by&lt;/code&gt; or &lt;code&gt;Approved-by&lt;/code&gt;, etc.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- `Signed-off-by: John &amp;lt;john@example.com&amp;gt;`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Breaking change:&lt;/strong&gt; Indicate breaking changes with a &lt;code&gt;“BREAKING CHANGE”&lt;/code&gt; footer or by adding a &lt;code&gt;!&lt;/code&gt; sign after the type/scope.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Message: `chore!: drop support for Node 6`
- Extended footer should be as follows:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ```markdown
    BREAKING CHANGE: Remove support for Node 6 as it lacks necessary features.
    ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Multi-paragraph Body:&lt;/strong&gt; Use multiple paragraphs in the body to explain the what, why and how of the commit changes in greater detail.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;fix: Resolve issue with user login

The previous implementation caused a login failure when the
user had special characters in their password. This commit
refactors the login validation to properly handle special 
characters.

Additional tests have been added to cover edge cases.
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;By following these conventions, you ensure your commit messages are informative, consistent, and helpful for anyone working on the project now and in the future.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Simplifying Commit Messages with Handy Tools
&lt;/h2&gt;

&lt;p&gt;To make sure your commit messages are consistent and clear, you can use tools like &lt;a href="https://github.com/Milo123459/glitter" rel="noopener noreferrer"&gt;Glitter&lt;/a&gt; or &lt;a href="http://commitizen.github.io/cz-cli/" rel="noopener noreferrer"&gt;Commitizen&lt;/a&gt;. These tools help you stick to a standardized format for your commit messages.&lt;/p&gt;

&lt;p&gt;For an extra layer of consistency, try &lt;a href="https://commitlint.js.org/#/" rel="noopener noreferrer"&gt;Commitlint&lt;/a&gt;. I had personally utilized this  and found it right for standardized commit messages. This tool checks your commit messages and throw an error if someone does not follow the guidelines, ensuring everyone on  the team stays on the same page.&lt;/p&gt;

&lt;p&gt;Many companies uses JIRA, ClickUp or any other project management tool for ticket IDs as commit message. This practice makes it easy to link and trace changes, keeping the codebase maintainable for future developers.&lt;/p&gt;

&lt;p&gt;Adding emojis to commit messages is also popular. I have put together a list of emojis and their meanings that you can use to make your commit messages more expressive. Check it out here: &lt;a href="https://gist.github.com/ayushsoni1010/cfc409ebabaae68b84a70306cc67c297" rel="noopener noreferrer"&gt;https://gist.github.com/ayushsoni1010/cfc409ebabaae68b84a70306cc67c297&lt;/a&gt;&lt;/p&gt;




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

&lt;p&gt;Mastering the art of writing effective commit messages is an invaluable skill that enhances collaboration and maintains the integrity of your codebase. By following these conventions, you ensure that your commit history is clear, informative, and easy to navigate. Whether you’re working alone or as part of a team, these practices will make your version control process more efficient and your codebase more maintainable. &lt;/p&gt;

&lt;p&gt;Remember, a little attention to detail in your commit messages can save countless hours in the future and contribute to a smoother development workflow for everyone involved. &lt;/p&gt;

&lt;p&gt;Happy committing🌱&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/" rel="noopener noreferrer"&gt;https://www.conventionalcommits.org/en/v1.0.0-beta.2/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/how-to-naming-conventions-for-git-branches/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/how-to-naming-conventions-for-git-branches/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://se-education.org/guides/conventions/git.html" rel="noopener noreferrer"&gt;https://se-education.org/guides/conventions/git.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cbea.ms/git-commit/" rel="noopener noreferrer"&gt;https://cbea.ms/git-commit/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git-interpret-trailers" rel="noopener noreferrer"&gt;https://git-scm.com/docs/git-interpret-trailers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://phoenixnap.com/kb/git-branch-name-convention" rel="noopener noreferrer"&gt;https://phoenixnap.com/kb/git-branch-name-convention&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/ayushsoni1010/cfc409ebabaae68b84a70306cc67c297" rel="noopener noreferrer"&gt;https://gist.github.com/ayushsoni1010/cfc409ebabaae68b84a70306cc67c297&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;That's all for today.&lt;br&gt;
If you enjoyed this content, please share your feedback.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://x.com/ayushsoni1010" rel="noopener noreferrer"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>commit</category>
      <category>writing</category>
    </item>
    <item>
      <title>How to install fastn on your local machine</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Wed, 03 May 2023 16:04:58 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/how-to-install-fastn-on-your-local-machine-5bd8</link>
      <guid>https://dev.to/ayushsoni1010/how-to-install-fastn-on-your-local-machine-5bd8</guid>
      <description>&lt;p&gt;After gaining experience in website development, it's time to broaden your skills and learn how to develop, build, and deploy your fastn apps to showcase your work to the world. Let's explore the installation process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OF_du2wI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjg6m22aybggtm5d0a5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OF_du2wI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjg6m22aybggtm5d0a5i.png" alt="description" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Introduction
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;fastn&lt;/code&gt; is a powerful web framework written in Rust that allows you to build interactive user interfaces, full-stack web applications, and content-centric websites. For developers and non-developers, building websites and framing the user interface using HTML, CSS, and JavaScript can sometimes be troublesome.&lt;/p&gt;

&lt;p&gt;What if a non-programmer wants to build their portfolio or any website? It would take a lot of time to learn these languages while building the overall project or any websites. In this blog, we will delve into the installation process of fastn in various ways based on different machines and explore the functionalities of both fastn and ftd.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌What's ftd?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ftd&lt;/code&gt; is a programming language for building beautiful user interfaces and content-centric websites. It is easy to learn and designed for everyone, not just for programmers, especially for non-programmers. Building websites and creating interfaces using HTML, CSS, and JavaScript can sometimes be challenging for both developers and non-developers.&lt;/p&gt;

&lt;p&gt;However, fastn provides a solution by offering a programming language called ftd that is designed with minimal syntax and is user-friendly that everyone can understand at first glance. It does not even look like a programming language and even non-programmers can quickly grasp its minimal syntax, which resembles markdown syntax and makes it highly human-readable and accessible.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌What's fastn?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;fastn&lt;/code&gt; is a web framework, a content management system, and even serves as an integrated development environment for &lt;code&gt;ftd&lt;/code&gt;. It is a web server that compiles &lt;code&gt;ftd&lt;/code&gt; to HTML, CSS, and JS. It allows you to deploy fastn applications on any static hosting provider, such as GitHub Pages, Vercel, fastn Cloud, or your own server.&lt;/p&gt;

&lt;p&gt;It also provides a lot of ready-made UI components that help to develop your websites faster in no time, and you can even create your custom components. fastn is used to work with ftd files, and it ships pre-built binaries for Linux, Mac, and Windows.&lt;/p&gt;

&lt;p&gt;To kickstart your journey with fastn, I recommend checking out the short video course available at &lt;strong&gt;&lt;a href="https://fastn.com/expander"&gt;fastn.com/expander&lt;/a&gt;&lt;/strong&gt;. This course provides a quick introduction to the basics of fastn and will help you get up to speed in no time.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Prerequisites
&lt;/h3&gt;

&lt;p&gt;To benefit the most from this article, the following pre-requisites are required:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub account&lt;/li&gt;
&lt;li&gt;Install Git on your machine and set up Git&lt;/li&gt;
&lt;li&gt;The latest cargo version is installed on your system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📌Installation of fastn
&lt;/h3&gt;

&lt;p&gt;Based on the machines, there are three ways to install fastn:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install fastn through the pre-built binary on &lt;strong&gt;Windows&lt;/strong&gt; (Recommended)&lt;/li&gt;
&lt;li&gt;Install fastn through the pre-built binary on &lt;strong&gt;MacOS/Linux&lt;/strong&gt; (Recommended)&lt;/li&gt;
&lt;li&gt;Install fastn using cargo&lt;/li&gt;
&lt;li&gt;Install fastn from source&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;💡 &lt;strong&gt;Recommendation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We recommend you install &lt;code&gt;fastn&lt;/code&gt; through &lt;code&gt;pre-built binary&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is the preferred method as it only requires downloading the binary and installing it on your local system.&lt;/p&gt;

&lt;h3&gt;
  
  
  👉Install fastn through the pre-built binary on &lt;strong&gt;Windows&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To install &lt;code&gt;fastn&lt;/code&gt; through the pre-built binary, follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the executable from the &lt;strong&gt;&lt;a href="https://github.com/fastn-stack/fastn/releases"&gt;Releases&lt;/a&gt;&lt;/strong&gt; page&lt;/li&gt;
&lt;li&gt;Click on the latest release&lt;/li&gt;
&lt;li&gt;Get the executable file for Windows on the releases page under Assets&lt;/li&gt;
&lt;li&gt;Create a folder named &lt;code&gt;FASTN&lt;/code&gt; in your &lt;strong&gt;C&lt;/strong&gt; drive&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;Settings&lt;/strong&gt; and search for &lt;strong&gt;Environmental Variable&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Check for &lt;strong&gt;Path&lt;/strong&gt; and double-click on it in the user variables&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;New&lt;/strong&gt; button and set a path for &lt;strong&gt;FASTN&lt;/strong&gt; in your machine's &lt;strong&gt;Environment Variable&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The recommended path would be &lt;code&gt;C:\FASTN&lt;/code&gt;, then apply settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---ZnnZUL_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://fastn.com/-/fastn.io/images/setup/windows-fastn-installation.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---ZnnZUL_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://fastn.com/-/fastn.io/images/setup/windows-fastn-installation.gif" alt="gif" width="600" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installation of fastn is completed. To verify, open the command prompt and execute the command &lt;code&gt;fastn&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you face any difficulty while installing fastn, check out the &lt;strong&gt;&lt;a href="https://youtu.be/lw-qVPCJgZs"&gt;youtube&lt;/a&gt;&lt;/strong&gt; video.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eJOa7Z8_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dchwhwnej9pllpjxysl9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eJOa7Z8_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dchwhwnej9pllpjxysl9.png" alt="description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  👉Install fastn through the pre-built binary on MacOS/Linux
&lt;/h3&gt;

&lt;p&gt;For MacOS, we have an installer script, you just need to copy and paste the given below script into the terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/fastn-stack/fastn/main/install.sh)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qSKH4W0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65mjgbmk4x258db13o2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qSKH4W0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65mjgbmk4x258db13o2t.png" alt="Image" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bXQBKqPf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i16h7i23cx390lyqn6gf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bXQBKqPf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i16h7i23cx390lyqn6gf.png" alt="description" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installation of fastn is completed. To verify, open the terminal and execute the command &lt;code&gt;fastn&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If you face any difficulty while installing fastn, check out the &lt;strong&gt;&lt;a href="https://youtu.be/cWdivkyoOTA"&gt;youtube&lt;/a&gt;&lt;/strong&gt; video&lt;/p&gt;




&lt;h3&gt;
  
  
  👉Install fastn using cargo
&lt;/h3&gt;

&lt;p&gt;If you have &lt;code&gt;cargo&lt;/code&gt; installed on your system, you can run the following command to install fastn.&lt;/p&gt;

&lt;p&gt;For more details on how to install cargo are given &lt;a href="https://doc.rust-lang.org/cargo/getting-started/installation.html"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo install fastn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  👉Install fastn from source
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;fastn&lt;/code&gt; is an open-source project. You can clone the fastn github repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/fastn-stack/fastn.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;fastn is implemented using Rust, using the 2021 edition, so the minimum supported Rust version (MSRV) is 1.65.0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd fastn
cargo test
cargo build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linux Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When building from source you will have to install SSL and SQLite dev packages:&lt;/p&gt;

&lt;p&gt;Once you have installed the &lt;code&gt;fastn&lt;/code&gt; you can start using &lt;code&gt;ftd&lt;/code&gt; files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install libsqlite3-dev libssl-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;code&gt;fastn&lt;/code&gt; is a powerful web framework that helps developers and non-developers create interactive user interfaces, full-stack web applications, and content-centric websites. Its ftd programming language has minimal syntax and is user-friendly. fastn comes with many ready-made UI components, and developers can create custom components too. It's a great tool for showcasing work to the world.&lt;/p&gt;

&lt;p&gt;Overall, the article provides a comprehensive guide to installing fastn on Windows, MacOS, and Linux. The guide recommends using the pre-built binary method for installation. It also covers how to install fastn using cargo or from source code.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Over to you
&lt;/h3&gt;

&lt;p&gt;Which static hosting providers do you use to host your fastn applications?&lt;/p&gt;

&lt;p&gt;Let me know in the comments😄&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet😀&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>fastn</category>
      <category>ftd</category>
      <category>webdev</category>
      <category>framework</category>
    </item>
    <item>
      <title>Deploy your React app using GitHub pages</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Tue, 04 Apr 2023 06:11:54 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/deploy-your-react-app-using-github-pages-526i</link>
      <guid>https://dev.to/ayushsoni1010/deploy-your-react-app-using-github-pages-526i</guid>
      <description>&lt;p&gt;After gaining experience in creating React apps, it's time to explore various deployment options available to showcase your work to the world. We have been using Create React App to develop our React applications, so let’s see what it has to offer for our deployment process.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Introduction
&lt;/h3&gt;

&lt;p&gt;React is a powerful JavaScript library for building interactive user interfaces. Once you have created your React app, the next step is to deploy it to a server so that it can be accessed by the users.&lt;/p&gt;

&lt;p&gt;Assuming you have built a React app and are now searching for a means to share it with the rest of the world, there are numerous options available to deploy a React app and it’s always good to try something new. One popular and feasible option is to make use of GitHub Pages.&lt;/p&gt;

&lt;p&gt;GitHub Pages is a free hosting service that allows you to easily deploy and share your web projects. So, why not take advantage of this option and give it a shot?&lt;/p&gt;

&lt;p&gt;In this blog post, we will go through several steps to deploy your React app using Github Pages.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;GitHub account&lt;/li&gt;
&lt;li&gt;Install Git on your machine and set up Git.&lt;/li&gt;
&lt;li&gt;Install Node.js&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📌Step 1: Creating the repository
&lt;/h3&gt;

&lt;p&gt;The first step is to create a new repository on GitHub for your React app. Once you have created your repository, clone it on your local machine using the Git command line tool for a Git GUI client.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oEIxY3oU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntqn8waru8eb5dhu0oiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oEIxY3oU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntqn8waru8eb5dhu0oiz.png" alt="Image" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Step 2: Create your React app
&lt;/h3&gt;

&lt;p&gt;After cloning your empty git repository, create a react app in the working of your git repository by the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  📌Step 3: Add the dependencies to your app
&lt;/h3&gt;

&lt;p&gt;Install the following package in your React app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;gh&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;pages&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  📌*&lt;strong&gt;&lt;em&gt;Step 4: Add configs to your react app&lt;/em&gt;&lt;/strong&gt;*
&lt;/h3&gt;

&lt;p&gt;Normally, our app will be deployed on a subdomain with our username on &lt;code&gt;github.io&lt;/code&gt; like any other app, so to keep our app well-informed about our root URL, we need to add a &lt;code&gt;homepage&lt;/code&gt; attribute to our &lt;code&gt;package.json&lt;/code&gt; file and assign the URL to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;homepage&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://{user-name}.github.io/{repo-name}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  📌Step 5: Build your React app
&lt;/h3&gt;

&lt;p&gt;Before you can deploy your React app to GitHub pages, you need to build it. In your &lt;code&gt;package.json&lt;/code&gt; file, add the &lt;code&gt;predeploy&lt;/code&gt; and &lt;code&gt;deploy&lt;/code&gt; keys under scripts to create a production-ready build of your app. This will create a &lt;code&gt;build&lt;/code&gt; directory in your project directory that contains the optimized and minified production build of your React app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;predeploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;npm run build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;deploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gh-pages -d build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;package.json&lt;/code&gt; file should be similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;homepage&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://ayushsoni1010.github.io/test-react-app-deploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test-react-app-deploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0.1.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;private&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dependencies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/jest-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^5.16.5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^13.4.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/user-event&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^13.5.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^18.2.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^18.2.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5.0.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;web-vitals&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^2.1.4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-scripts start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-scripts build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-scripts test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;eject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-scripts eject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;predeploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;npm run build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;deploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gh-pages -d build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;eslintConfig&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;extends&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-app/jest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;browserslist&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;gt;0.2%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;not dead&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;not op_mini all&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;last 1 chrome version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;last 1 firefox version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;last 1 safari version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;devDependencies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gh-pages&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^5.0.0&lt;/span&gt;&lt;span class="dl"&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;h3&gt;
  
  
  📌Step 6: Deploy your React app
&lt;/h3&gt;

&lt;p&gt;Now, all we need is to run &lt;code&gt;npm run deploy&lt;/code&gt; command in the terminal every time we make changes and want to deploy our app with the latest changes and it will be up and running on the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="nx"&gt;deploy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will create a branch named &lt;code&gt;gh-pages&lt;/code&gt;. After the build finishes, it pushes the changes to the &lt;code&gt;gh-pages&lt;/code&gt; branch on the remote repository and hosts your app.&lt;/p&gt;

&lt;p&gt;Now, it should be deployed to your GitHub repository after some time. To acquire the URL, go to your repository and click on &lt;strong&gt;Settings&lt;/strong&gt; and go to &lt;strong&gt;Pages&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Boom! Your site is live on GitHub Pages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TwkvgvoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un94xuk86yp1cbbs6p1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TwkvgvoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un94xuk86yp1cbbs6p1o.png" alt="Image" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Step 7: Commit and Push your changes to GitHub
&lt;/h3&gt;

&lt;p&gt;Once you committed the changes, you need to push your changes to GitHub.&lt;/p&gt;

&lt;p&gt;Run the following commands to push your changes to the remote repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;your commit message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;push&lt;/span&gt; &lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Deploying your React app to GitHub Pages is a simple and easy way to share your app with the world. By following these steps, you can quickly deploy your app and make it available to anyone with an internet connection. GitHub Pages is a great option for small projects, personal websites, or demo sites. If you have a complex app or need more control over your hosting environment, you may want to consider other hosting options. But for simpler React apps, GitHub Pages is an excellent choice that is both free and easy to use.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌Over to you
&lt;/h3&gt;

&lt;p&gt;Have you used &lt;code&gt;github-pages&lt;/code&gt; to host your React applications?&lt;/p&gt;

&lt;p&gt;Let me know in the comments😄&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>githubpages</category>
    </item>
    <item>
      <title>Build an API with Serverless Functions in Next.js</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Sat, 01 Apr 2023 05:49:37 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/build-an-api-with-serverless-functions-in-nextjs-52n1</link>
      <guid>https://dev.to/ayushsoni1010/build-an-api-with-serverless-functions-in-nextjs-52n1</guid>
      <description>&lt;p&gt;Next.js is a React framework that provides two ways of rendering React components into HTML pages - &lt;strong&gt;server-side rendering(SSR)&lt;/strong&gt; and &lt;strong&gt;static site generation(SSG).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In SSR, React components are rendered into HTML pages on the server after a page request comes from the browser, while in SSG, React components are rendered into HTML pages at build time.&lt;/p&gt;

&lt;p&gt;Regardless of which method is used, the rendered HTML pages are sent to the browser, making the app behave like a single-page application(SPA). This is in contrast to client-side rendering, where components are rendered in the browser. With Next.js, you can enjoy the benefits of both SSG and SSR, such as improved performance and better SEO. In addition to these features, Next.js also offers Serverless Functions, which we’ll be covering in this article.&lt;/p&gt;

&lt;p&gt;We'll cover the Next.js page and dynamic routes and learn about Next.js API and dynamic API routes, all while running Serverless Functions on Vercel, a platform designed specifically for Next.js applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💎Introduction to Serverless Functions in Next.js&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The term “serverless functions” is just a naming convention. AWS calls it Lambda Functions, but Vercel calls them their Serverless Functions, they are the same thing.&lt;/p&gt;

&lt;p&gt;Serverless Functions are not directly a part of the Next.js API. However, Next.js provides developers with API routes that can be deployed as Vercel Serverless Functions and this is the crux of this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💎Pre-requisites&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To benefit the most from this article, the following pre-requisites are required:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic understanding of JavaScript&lt;/li&gt;
&lt;li&gt;Basic understanding of Next.js&lt;/li&gt;
&lt;li&gt;Basic understanding of API design&lt;/li&gt;
&lt;li&gt;The latest Node version is installed on your system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💎Setting up our application&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We will start by bootstrapping the Next.js application and using &lt;code&gt;create-next-app&lt;/code&gt; to automatically set everything up. To create a Next.js project, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the installation is complete, start your app by running &lt;code&gt;yarn dev&lt;/code&gt;. When you visit &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;localhost:3000&lt;/a&gt; you will get:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;strong&gt;💎Page routes in Next.js&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In Next.js, each page is driven by a component. For example, an “About” page will have an &lt;code&gt;About&lt;/code&gt; component. Each page component has a file inside a &lt;code&gt;page&lt;/code&gt; folder, thus, the file name and location of each page component are tied up to the particular page’s route.&lt;/p&gt;

&lt;p&gt;To elaborate on this, navigate your browser to &lt;a href="http://localhost:3000/about" rel="noopener noreferrer"&gt;localhost:3000/about&lt;/a&gt; and you will get:&lt;/p&gt;

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

&lt;p&gt;The &lt;code&gt;404&lt;/code&gt; page shown above simply shows that Next.js cannot find a component in the &lt;code&gt;page&lt;/code&gt; folder called &lt;code&gt;about&lt;/code&gt;. This is because we have not created an &lt;code&gt;About&lt;/code&gt; component in the &lt;code&gt;pages&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;To resolve this, create an &lt;code&gt;about.js&lt;/code&gt; file inside the &lt;code&gt;pages&lt;/code&gt; directory and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, revisit to &lt;a href="http://localhost:3000/about" rel="noopener noreferrer"&gt;localhost:3000/about&lt;/a&gt; and you get:&lt;/p&gt;

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

&lt;p&gt;When we created the &lt;code&gt;About&lt;/code&gt; component in the &lt;code&gt;pages&lt;/code&gt; folder, Next.js automatically created a route to server the &lt;code&gt;About&lt;/code&gt; component. Thus, the route name is tied to the filename.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💎Dynamic routes in Next.js&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next.js pages support &lt;a href="https://nextjs.org/docs/routing/dynamic-routes" rel="noopener noreferrer"&gt;dynamic routes&lt;/a&gt;. This is useful because complex applications require more than just defining routes by using predefined paths.&lt;/p&gt;

&lt;p&gt;In Next.js, you can add brackets to a page component name, &lt;code&gt;[param.js]&lt;/code&gt; to create a dynamic route for example. The page can be accessed via its dynamic route: &lt;code&gt;pages/users/[param].js&lt;/code&gt;. Here, &lt;code&gt;[param]&lt;/code&gt; is the page’s id, slug, pretty URLs, etc. Any route like &lt;code&gt;/users/1&lt;/code&gt; or &lt;code&gt;/users/abcdef&lt;/code&gt; can be matched.&lt;/p&gt;

&lt;p&gt;Next.js will send the matched path parameter as a query parameter to the page and if there are other query parameters, Next.js will link the matched path parameter with them.&lt;/p&gt;

&lt;p&gt;To elaborate on this, the matched route &lt;code&gt;/users/abcdef&lt;/code&gt; of dynamic route &lt;code&gt;pages/users/[param].js&lt;/code&gt;, will have the query object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;param&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abcdef&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, the matched route &lt;code&gt;/users/abcdef?foo=bar&lt;/code&gt; of a dynamic route, &lt;code&gt;pages/users[param].js&lt;/code&gt;, will have the following query object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;param&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abcdef&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your application, create a &lt;code&gt;user&lt;/code&gt; folder, and inside it create a component named &lt;code&gt;[username].js&lt;/code&gt;. Add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRouter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRouter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;username&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello! Welcome &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when you visit &lt;a href="http://localhost:3000/users/ayushsoni1010" rel="noopener noreferrer"&gt;http://localhost:3000/users/ayushsoni1010&lt;/a&gt;, you get the display content would be &lt;code&gt;Hello! Welcome ayushsoni1010&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;From the above demonstration, you see that Next.js matched &lt;code&gt;/users/ayushsoni1010&lt;/code&gt; with the dynamic route &lt;code&gt;pages/users/[username].js&lt;/code&gt;. Thus whatever &lt;code&gt;username&lt;/code&gt; is passed in the route will be displayed on the page. You can try out different usernames.&lt;/p&gt;

&lt;p&gt;In addition to it, creating and serving pages with the page routes, Next.js can create APIs with the API routes. Based on our knowledge gained so far, let’s learn about Next.js API routes in the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💎 API Routing with Next.js Serverless Functions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://nextjs.org/blog/next-9" rel="noopener noreferrer"&gt;API routes were introduced in Next.js v9&lt;/a&gt;. They enable us to build backend application endpoints, leveraging hot reloading, and a unified build pipeline in the process.&lt;/p&gt;

&lt;p&gt;What this means is that Next&amp;gt;v9 encapsulates both the frontend and backend. We can rapidly develop full-stack React and Node.js applications that scale effortlessly.&lt;/p&gt;

&lt;p&gt;While the page routes serve Next.js pages as web pages, Next.js API routes are treated as an endpoint. The API routes live inside the &lt;code&gt;/pages/api&lt;/code&gt; folder and Next.js maps any file inside the folder to &lt;code&gt;/api/*&lt;/code&gt; as an endpoint.&lt;/p&gt;

&lt;p&gt;This feature is very interesting because it enables Next.js to render data on the frontend that is sorted in the Next.js app or render data that is fetched using Next.js API routes.&lt;/p&gt;

&lt;p&gt;By bootstrapping your application with &lt;code&gt;creat-next-app&lt;/code&gt;, Next.js automatically creates an example API route, the &lt;code&gt;/pages/api/hello.js&lt;/code&gt; file, for you. Inside &lt;code&gt;/pages/api/hello.js&lt;/code&gt;, Next.js creates and exports a function named &lt;code&gt;handler&lt;/code&gt; that returns a JSON object.&lt;/p&gt;

&lt;p&gt;You can access this endpoint via the browser by navigating to &lt;a href="http://localhost:3000/api/hello" rel="noopener noreferrer"&gt;http://localhost:3000/api/hello&lt;/a&gt; and the following JSON is returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;💎The request handler function&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As seen above, to create a Next.js API route, you need to export a request handler function as default. The request handler function receives two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;req&lt;/code&gt;: an object that is an instance of &lt;code&gt;http.IncomingMessage&lt;/code&gt;, and some &lt;a href="https://nextjs.org/docs/api-routes/request-helpers" rel="noopener noreferrer"&gt;prebuilt middlewares&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;res&lt;/code&gt;: an object that is an instance of &lt;code&gt;http.ServerResponse&lt;/code&gt;, and some &lt;a href="https://nextjs.org/docs/api-routes/response-helpers" rel="noopener noreferrer"&gt;helper functions&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To build an API with the API route, create a folder called &lt;code&gt;data&lt;/code&gt; in the root directory. Create a &lt;code&gt;post.json&lt;/code&gt; file inside the data folder with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am title 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from post 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am title 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from post 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am title 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from post 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am title 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from post 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am title 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from post 5&lt;/span&gt;&lt;span class="dl"&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;p&gt;Now, in the &lt;code&gt;pages/api&lt;/code&gt; folder, create a new file called posts.js with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Next.js API route support: https://nextjs.org/docs/api-routes/introduction&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../data/posts.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the API route above, the handler function imports the JSON data posts and returns them as a response to a &lt;code&gt;GET&lt;/code&gt; request. When you query for this data by visiting &lt;a href="http://localhost:3000/api/posts" rel="noopener noreferrer"&gt;http://localhost:3000/api/posts&lt;/a&gt; from the browser, you get:&lt;/p&gt;

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

&lt;p&gt;You can use the &lt;code&gt;request.method&lt;/code&gt; object as seen below to handle other HTTP requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;//...&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;//...&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PUT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;//...&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;//...&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;405&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Method not allowed&lt;/span&gt;
      &lt;span class="k"&gt;break&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;h3&gt;
  
  
  &lt;strong&gt;💎Dynamic API routes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Like page routes, Next.js API routes support dynamic routes and dynamic API routes follows the same file naming conventions and rules as page routes.&lt;/p&gt;

&lt;p&gt;To elaborate more on this, create a &lt;code&gt;posts&lt;/code&gt; folder inside the &lt;code&gt;pages/api&lt;/code&gt; folder. Create a file named &lt;code&gt;[postid].js&lt;/code&gt; inside the &lt;code&gt;posts&lt;/code&gt; folder and paste the following code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Next.js API route support: https://nextjs.org/docs/api-routes/introduction&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../../data/posts.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;postid&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postid&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, Next.js automatically matched the &lt;code&gt;/posts/2&lt;/code&gt; with the dynamic route &lt;code&gt;pages/api/posts/[postid].js&lt;/code&gt;. Whichever post &lt;code&gt;id&lt;/code&gt; is passed to the route &lt;code&gt;/posts/[postid]&lt;/code&gt;: &lt;code&gt;/post/2&lt;/code&gt;, &lt;code&gt;/post/3&lt;/code&gt;, &lt;code&gt;/post/4&lt;/code&gt;, etc. will be available in the &lt;code&gt;req.query&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;The request handler function above retrieves the passed post &lt;code&gt;id&lt;/code&gt; from the &lt;code&gt;req.query&lt;/code&gt; object, finds the post in the &lt;code&gt;posts&lt;/code&gt; array, and sends it to the client.&lt;/p&gt;

&lt;p&gt;So to get the post with an &lt;code&gt;id&lt;/code&gt; of &lt;code&gt;2&lt;/code&gt;, navigate your browser to &lt;a href="http://localhost:3000/api/posts/2" rel="noopener noreferrer"&gt;&lt;code&gt;http://localhost:3000/api/posts/2&lt;/code&gt;&lt;/a&gt;. You will get:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  💎Advantages of API routes
&lt;/h3&gt;

&lt;p&gt;Next.js API routes are deployed as Serverless Functions in Vercel. This means they can be deployed to many regions across the world to improve latency and availability.&lt;/p&gt;

&lt;p&gt;Also, as Serverless Functions, they are cost-effective and enable you to run your code on demand. This removes the need to manage infrastructure, provision servers, or upgrade hardware.&lt;/p&gt;

&lt;p&gt;Another benefit of API routes is that they scale very well. Finally, they do not specify CORS by default because they are &lt;code&gt;same-origin&lt;/code&gt;, however, you can customize this behavior by using the &lt;a href="https://github.com/vercel/next.js/blob/canary/examples/api-routes-cors/pages/api/cors.ts" rel="noopener noreferrer"&gt;CORS request helper&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  💎Over to you
&lt;/h3&gt;

&lt;p&gt;Which APIs have you built with Next.js API routes?&lt;/p&gt;

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

&lt;p&gt;In this article, we learned about an interesting and powerful Next.js feature — API routes. We began by learning about the Next.js page route and delved into API routes. We also learned how to build an API using Next API routes, deployed as Vercel’s Serverless Functions.&lt;/p&gt;

&lt;p&gt;I do hope that at the end of this article, you can build APIs using Next.js APIs Route.&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010" rel="noopener noreferrer"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>api</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Supercharge your React app with useSWR</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Wed, 29 Mar 2023 23:04:42 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/supercharge-your-react-app-with-useswr-kmb</link>
      <guid>https://dev.to/ayushsoni1010/supercharge-your-react-app-with-useswr-kmb</guid>
      <description>&lt;h3&gt;
  
  
  🚩Introduction
&lt;/h3&gt;

&lt;p&gt;As a developer, you might find it challenging to handle error cases while writing code. Fetching and caching data efficiently is essential for improving app performance and reducing loading time. Whether you are working with APIs, remote data fetching, or from other sources, getting data into your app quickly and reliably can be a major challenge. In this blog, we will explore how to use &lt;strong&gt;useSWR&lt;/strong&gt;, compare its existing hooks, and show why it's better.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩Pre-requisites
&lt;/h3&gt;

&lt;p&gt;This article assumes that you are familiar with JavaScript, React, and Next.js. It would be helpful to have a good understanding of hooks, asynchronous JavaScript, and creating custom hooks. Let's dive straight in!&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩How useSWR works
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;useSWR&lt;/strong&gt;&lt;br&gt;
 hook takes two parameters: key and fetcher. The key is something that uniquely identifies the data to be fetched, usually the API URL, while the fetcher is a function that returns the data. The hook returns two values: data and error, representing the request's status. These two values can be used to set a loading state and an error fallback, respectively. The significant perk of the &lt;strong&gt;useSWR&lt;/strong&gt;&lt;br&gt;
 hook offers is how it simplifies the data fetching logic, delivering API data or returning an error response with just two lines of code. Furthermore, for each request made, a cached version is first returned while the server revalidates the request and returns updated data immediately after revalidation, helping optimize the web app and improve speed.&lt;/p&gt;
&lt;h3&gt;
  
  
  🚩Getting started with useSWR
&lt;/h3&gt;

&lt;p&gt;The name &lt;strong&gt;SWR&lt;/strong&gt; is derived from the concept called "stale-while-revalidate," which is an HTTP cache invalidation strategy popularized by HTTP RFC 5861. It performs data fetching in 3 steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Returns cached data first (stale)&lt;/li&gt;
&lt;li&gt;Sends the fetch request (revalidate)&lt;/li&gt;
&lt;li&gt;Returns the up-to-date data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hook comes with a display of benefits which includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplicity of Logic&lt;/li&gt;
&lt;li&gt;Lightweight&lt;/li&gt;
&lt;li&gt;Offers revalidation&lt;/li&gt;
&lt;li&gt;Easy pagination&lt;/li&gt;
&lt;li&gt;Supports TypeScript and a host of other perks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get started with &lt;strong&gt;useSWR,&lt;/strong&gt; you first need to install it as a dependency in your React or Next project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="nx"&gt;swr&lt;/span&gt; 
&lt;span class="nx"&gt;or&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;swr&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, you can import the &lt;strong&gt;useSWR&lt;/strong&gt; hook and use it in your components to fetch and cache data.&lt;/p&gt;

&lt;p&gt;Let’s understand it through an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;swr&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error fetching data&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading data...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;p&gt;As you can see, useSWR provides a more straightforward and concise way to fetch and cache data in React. It handles caching and error handling automatically and provides options for polling and deduplication.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩Pagination
&lt;/h3&gt;

&lt;p&gt;Pagination is a crucial feature of modern web applications. It helps users to navigate through large amounts of data with ease. In React, the SWR library provides an API called useSWRInfinite for implementing complex pagination patterns. However, for common pagination patterns, useSWR is sufficient.&lt;/p&gt;

&lt;p&gt;Let’s take an example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Page&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/data?page=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fetcher&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// ... handle loading and error states&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Pagination&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;pageIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPageIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// The API URL includes the page index, which is a React state.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/data?page=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;pageIndex&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fetcher&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// ... handle loading and error states&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setPageIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageIndex&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Previous&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setPageIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageIndex&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Next&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, this works if the API has a provision for pagination. Also, since SWR provides caching, the preceding and previous pages are pre-fetched or preloaded when rendered in the abstracted div element. Other types of pagination such as Infinite Loading can also be achieved easily using SWR.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩Comparing useSWR and existing hooks
&lt;/h3&gt;

&lt;p&gt;One common approach to fetching and caching remote data in React and Next is to use &lt;strong&gt;useEffect&lt;/strong&gt; and &lt;strong&gt;useState&lt;/strong&gt; hooks.&lt;/p&gt;

&lt;p&gt;Let’s understand it through an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setError&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setError&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error fetching data&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading data...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;p&gt;While this approach works, it has some limitations. For example, it requires more code to handle caching and error handling. It also doesn't provide options for polling or deduplication. &lt;/p&gt;

&lt;p&gt;Now let’s compare this with &lt;strong&gt;useSWR&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;swr&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error fetching data&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading data...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;p&gt;As you can see that useSWR provides a simpler and more concise way to fetch and cache data in React or Next. It handles caching and error handling automatically and provides options for polling and deduplication.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩Performance comparison
&lt;/h3&gt;

&lt;p&gt;To compare the performance of UseSWR with &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt;, we'll use the same API endpoint for both approaches: &lt;strong&gt;&lt;a href="https://jsonplaceholder.typicode.com/todos"&gt;jsonplaceholder.typicode.com/todos&lt;/a&gt;&lt;/strong&gt;. We'll measure the time it takes to fetch and display 100 to-do items from the API.&lt;/p&gt;

&lt;p&gt;Here's the code for fetching and displaying todo items using &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;TodoList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;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;p&gt;Using this approach, it took an average of 150-200 milliseconds to fetch and display the 100 to-do items.&lt;/p&gt;

&lt;p&gt;Now let's compare this with UseSWR:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;swr&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;TodoList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSWR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error fetching data&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading data...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;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;p&gt;Using UseSWR, it took an average of 100-150 milliseconds to fetch and display the same 100 to-do items.&lt;/p&gt;

&lt;p&gt;As you can see, UseSWR performs better than &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt; in terms of speed, even though it handles caching and error handling automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  Over to you
&lt;/h3&gt;

&lt;p&gt;Have you used the &lt;strong&gt;useSWR&lt;/strong&gt; hook before?&lt;/p&gt;

&lt;p&gt;Let me know in the comments😄&lt;/p&gt;

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

&lt;p&gt;The SWR hook saves us the stress of writing our own logic for data fetching, making our code a lot cleaner and simpler. A better option is to use the &lt;code&gt;useEffect&lt;/code&gt; hook which perfects for static generated sites. Furthermore, it offers revalidation, and even more advanced options such as custom caching, middleware, and TypeScript support. Feel free to check out the &lt;strong&gt;&lt;a href="https://swr.vercel.app/docs/getting-started"&gt;official documentation&lt;/a&gt;&lt;/strong&gt; to learn more.&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>hooks</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why is Nginx called a “reverse” proxy?</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Tue, 28 Mar 2023 06:41:32 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/why-is-nginx-called-a-reverse-proxy-5c74</link>
      <guid>https://dev.to/ayushsoni1010/why-is-nginx-called-a-reverse-proxy-5c74</guid>
      <description>&lt;h3&gt;
  
  
  🔥&lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Nginx is a highly performant, scalable, and reliable open-source web server software that is frequently utilized as a "reverse proxy.” But why is it labeled as a "reverse" proxy which raises the question? &lt;/p&gt;

&lt;p&gt;Many companies use proxy servers to route and secure traffic between networks. There is often confusion, however, on how this differs from a reverse proxy. In this blog, we will be exploring the origins of the term “reverse” and “forward” proxy and understanding how Nginx functions as a reverse proxy.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔥&lt;strong&gt;Overview of Forward and Reverse Proxy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, let's start with the basics of what a proxy server is. A proxy server, sometimes referred to as a “forward” proxy, is a server that acts as an intermediary between clients and other servers on the network. When a client makes a request, the forward proxy intercepts the request and forwards it to the appropriate server on behalf of the client. By doing so, the client’s identity and location are hidden, convert and mask IP addresses, block unknown traffic from the server and the server’s response is sent back to the forward proxy, which in turn forwards it back to the client.&lt;/p&gt;

&lt;p&gt;Now, let's dive into the concept of a "reverse" proxy. A reverse proxy is a type of proxy server. Unlike a traditional proxy server, which is used to protect clients, a reverse proxy is used to protect servers. A reverse proxy is not used to serve client requests directly. Instead, it acts as a gateway to servers that are behind it, allowing those servers to receive client requests without directly exposing them to the internet.&lt;/p&gt;

&lt;p&gt;The diagram below shows the differences between a &lt;strong&gt;forward proxy&lt;/strong&gt; and a &lt;strong&gt;reverse proxy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1eY8QxPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/76895975/228149345-fdbee27e-5628-40a9-9798-83663af68055.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1eY8QxPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/76895975/228149345-fdbee27e-5628-40a9-9798-83663af68055.png" alt="image" width="800" height="850"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A forward proxy is commonly used for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid browser restrictions&lt;/li&gt;
&lt;li&gt;Block access to certain content&lt;/li&gt;
&lt;li&gt;Protect clients&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A reverse proxy is good for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protect servers&lt;/li&gt;
&lt;li&gt;Load balancing&lt;/li&gt;
&lt;li&gt;Caching static contents&lt;/li&gt;
&lt;li&gt;Encrypt and Decrypt SSL communications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP/2, TCP, and UDP protocols.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔥&lt;strong&gt;Why is Nginx called a “reverse” proxy?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Nginx is called a reverse proxy because it acts as an intermediary server between clients and backend servers, intercepting responses from the backend servers and forwarding them to the appropriate clients. In this way, Nginx functions as a reverse proxy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L-JIYSCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/76895975/228149289-7627a407-ef54-497c-bd43-b037dd00a19b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L-JIYSCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/76895975/228149289-7627a407-ef54-497c-bd43-b037dd00a19b.png" alt="image" width="720" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔥Benefits of using Nginx as a reverse proxy:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced security:&lt;/strong&gt; Nginx can act as a firewall, blocking malicious traffic and protecting backend servers from attack.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High availability:&lt;/strong&gt; Nginx can be configured to distribute traffic among multiple backend servers, ensuring high availability and reducing the risk of downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified management:&lt;/strong&gt; Nginx can be used to serve multiple domains or applications from a single server and making it a highly efficient solution for managing complex web environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load balancing:&lt;/strong&gt; Nginx can distribute incoming traffic across multiple backend servers, which can improve performance and ensure high availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL/TLS termination:&lt;/strong&gt; Nginx can terminate SSL/TLS connections, which can offload processing from backend servers and improve performance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🔥Over to you:
&lt;/h3&gt;

&lt;p&gt;Which proxy you will use: Reverse proxy or HAProxy?&lt;/p&gt;

&lt;p&gt;Let me know in the comments: which and why🤔&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this🔥😉.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>webservers</category>
      <category>nginx</category>
      <category>network</category>
    </item>
    <item>
      <title>Crafting Effective Chaos Error Messages</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Sun, 26 Mar 2023 19:19:25 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/crafting-effective-chaos-error-messages-i52</link>
      <guid>https://dev.to/ayushsoni1010/crafting-effective-chaos-error-messages-i52</guid>
      <description>&lt;h2&gt;
  
  
  💡Introduction
&lt;/h2&gt;

&lt;p&gt;Error messages are a common part of our online experience. Whenever a server is down, we lose internet connection, or we forget to fill out information on a form, we receive an error message. However, the classic "Something went wrong" message is not very informative. What exactly went wrong?&lt;/p&gt;

&lt;p&gt;It's important to understand what happened and how to fix it. Therefore, in chaos engineering, error messages should be more meaningful and provide clear instructions on how to resolve the issue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bcfyi35k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/280iyx1f4zcyyaiw7mcq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bcfyi35k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/280iyx1f4zcyyaiw7mcq.png" alt="Image" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💡What makes a bad error message?
&lt;/h2&gt;

&lt;p&gt;Error messages are part of our daily lives online. They inform us when something goes wrong, and help us understand what happened and how to fix it. However, not all error messages are created equal. A bad error message can leave us frustated, confused, and unable to resolve the issue at hand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DqWRkBol--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so8vqzsel5xy8k5sz9jg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DqWRkBol--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so8vqzsel5xy8k5sz9jg.png" alt="Image" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  💡Here are some common characteristics:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uninformative&lt;/strong&gt;: Error messages that simply state "Something went wrong" or "Error 404" without any further explanation or context are not helpful. They don't tell us what went wrong or how to fix it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technical jargon&lt;/strong&gt;: Error messages that are full of technical terms or jargon that the user may not be familiar with can be intimidating and confusing. Users shouldn't need a degree in computer science to understand what went wrong.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blaming&lt;/strong&gt;: Error messages that blame the user for the issue can be frustrating and unhelpful. Instead of pointing fingers, error messages should focus on providing solutions and clear next steps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inconsistent&lt;/strong&gt;: Error messages that look different from the rest of the website or application, or that are poorly designed, can be confusing and unprofessional. They should be consistent in style and design, and should be easy to read and understand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By avoiding these common pitfalls, we can create error messages that are clear, informative, and helpful for users.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡What makes a good error message?
&lt;/h2&gt;

&lt;p&gt;A good error message should be clear and concise, explaining what went wrong in a way that the user can understand. It should also suggest a solution or actions the user can take to resolve the issue. Additionally, a good error message should be friendly and not use technical jargon that the user may not be familiar with.&lt;/p&gt;

&lt;p&gt;When crafting error messages, it's important to consider the context in which they will be displayed. For example, an error message displayed to a client user may need to be worded differently than an error message displayed to a developer.&lt;/p&gt;

&lt;p&gt;By carefully considering the content and tone of error messages, we can create a better user experience and help users troubleshoot issues more effectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TUL7yskk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tplamvfjjvf5dgbcup0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TUL7yskk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tplamvfjjvf5dgbcup0l.png" alt="Image" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  💡Here are some common characteristics:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clarify what happened and why:&lt;/strong&gt; Make it super clear what did or didn’t happen. This can be done with a combination of visuals and text to explain errors and their causes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reassure users:&lt;/strong&gt; Let them know what was not affected by the error, such as saved drafts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be empathetic:&lt;/strong&gt; Use "please" when appropriate to show understanding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Help users fix the issue:&lt;/strong&gt; Give them clear instructions for fixing the issue or direct them to a knowledge base resource or article with a descriptive link like, “Learn how to resolve this” or “How do I fix this?”&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always give a way out:&lt;/strong&gt; If the problem persists or could reoccur, give them a Customer Care contact option.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡Over to you
&lt;/h2&gt;

&lt;p&gt;What's the best and worst error message you've seen?👀&lt;/p&gt;

&lt;p&gt;Wrong answers only🫠&lt;br&gt;
Let me know in the comments😀&lt;/p&gt;

&lt;p&gt;💡 Article Reference: &lt;a href="https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f"&gt;https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet 😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey 🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this 🔥 😉.&lt;/p&gt;

</description>
      <category>api</category>
      <category>javascript</category>
      <category>errors</category>
      <category>webdev</category>
    </item>
    <item>
      <title>HTTP Status Codes</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Sat, 25 Mar 2023 20:11:24 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/http-status-codes-57a1</link>
      <guid>https://dev.to/ayushsoni1010/http-status-codes-57a1</guid>
      <description>&lt;h2&gt;
  
  
  What are the most common HTTP status codes?
&lt;/h2&gt;

&lt;p&gt;HTTP status codes are essential in understanding the response returned by a server after making an HTTP request. They provide the information about the status of the request and response from the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎯HTTP response codes are categorized into five groups:
&lt;/h3&gt;

&lt;p&gt;Informational (100-199)&lt;/p&gt;

&lt;p&gt;Success (200-299)&lt;/p&gt;

&lt;p&gt;Redirection (300-399)&lt;/p&gt;

&lt;p&gt;Client Error (400-499)&lt;/p&gt;

&lt;p&gt;Server Error (500-599)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mZGpcmIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0qseogbrkgereae48nu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mZGpcmIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0qseogbrkgereae48nu.png" alt="Image" width="800" height="694"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🎯Here are some of the most common HTTP status codes:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;200 OK: This status code indicates that the request was successful.&lt;/li&gt;
&lt;li&gt;404 Not Found: This status code indicates that the requested resource could not be found on the server.&lt;/li&gt;
&lt;li&gt;500 Internal Server Error: This status code indicates that there was an error on the server that prevented the request from being fulfilled.&lt;/li&gt;
&lt;li&gt;401 Unauthorized: This status code indicates that the client is not authorized to access the requested resource.&lt;/li&gt;
&lt;li&gt;403 Forbidden: This status code indicates that the client does not have permission to access the requested resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These codes are just a few examples of the many HTTP status codes that exist. The exact list of most common HTTP status codes can vary depending on the context and the specific application.&lt;/p&gt;

&lt;h3&gt;
  
  
  🤔&lt;strong&gt;Over to you:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;HTTP status code 401 is for Unauthorized. Can you explain the difference between authentication and authorization, and which one code 401 check for?👀&lt;/p&gt;

&lt;p&gt;Let me know in the comments😀&lt;/p&gt;

&lt;h3&gt;
  
  
  🎯&lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;HTTP status codes are essential in understanding the response returned by a server after making an HTTP request. By categorizing the codes and having a clear set of definitions for each, developers can quickly identify and troubleshoot issues with their applications.&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;If you enjoyed this content, please share your feedback and consider retweeting the first tweet 😀.&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet and document my coding journey 🌸.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more content like this 🔥 😉.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>protocol</category>
      <category>http</category>
      <category>beginners</category>
    </item>
    <item>
      <title>MVC, MVP, MVVM, MVVM-C, and VIPER architecture patterns</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Fri, 24 Mar 2023 13:20:25 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/mvc-mvp-mvvm-mvvm-c-and-viper-architecture-patterns-1l3g</link>
      <guid>https://dev.to/ayushsoni1010/mvc-mvp-mvvm-mvvm-c-and-viper-architecture-patterns-1l3g</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What distinguishes MVC, MVP, MVVM, MVVM-C, and VIPER architecture patterns from each other?&lt;/strong&gt;
&lt;/h2&gt;

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

&lt;p&gt;When it comes to software development, choosing the right architecture pattern can make a huge difference in the quality and maintainability of the codebase. There are several architecture patterns to choose from, including MVC, MVP, MVVM, MVVM-C, and VIPER. While all of these patterns share some similarities, they each have their own unique characteristics and are best suited for different types of applications. These architectural patterns are among the most commonly used in development.&lt;/p&gt;

&lt;p&gt;Developers have introduced them to overcome the limitations of earlier patterns. So how do they differ?🤔&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cLDm0XlZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywxhu75r11mjtjd3ht1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cLDm0XlZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywxhu75r11mjtjd3ht1j.png" alt="Architecture" width="800" height="1052"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡MVC (Model-View-Controller)
&lt;/h2&gt;

&lt;p&gt;MVC is one of the most well-known and widely used architectural patterns. It separates the application into three main components: the model, the view, and the controller. The model represents the data and the business logic, the view is responsible for rendering the user interface, and the controller acts as the intermediary between the model and the view.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡MVP (Model-View-Presenter)
&lt;/h2&gt;

&lt;p&gt;MVP is similar to MVC, but with a slightly different approach. In MVP, the presenter acts as an intermediary between the model and the view, rather than the controller. The presenter is responsible for updating the view with data from the model, and for handling user input and events.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡MVVM (Model-View-ViewModel)
&lt;/h2&gt;

&lt;p&gt;MVVM is another architectural pattern that is gaining popularity. It is similar to MVP, but with the addition of a view model. The view model is responsible for managing the state of the view, as well as providing data from the model to the view. This pattern is often used in applications that require complex user interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡MVVM-C (Model-View-ViewModel-Coordinator)
&lt;/h2&gt;

&lt;p&gt;MVVM-C is a variation of MVVM that adds a coordinator to the mix. The coordinator is responsible for handling navigation between different screens or views within the application. This pattern is useful for applications that have multiple screens or views that need to be managed.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡VIPER (View-Interactor-Presenter-Entity-Router)
&lt;/h2&gt;

&lt;p&gt;VIPER is a relatively new architectural pattern that has gained popularity in recent years. It is similar to MVC, but with the addition of several new components, including the interactor, entity, and router. The interactor is responsible for handling business logic, the entity represents the data, and the router handles navigation between different screens or views.&lt;/p&gt;

&lt;h2&gt;
  
  
  🫡Common points to remember:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;MVC, the oldest pattern, dates back almost 50 years&lt;/li&gt;
&lt;li&gt;Every pattern has a “view” (V) responsible for displaying the user content interface and receiving the user input&lt;/li&gt;
&lt;li&gt;Most patterns include a “model” (M) to manage the business data and logic&lt;/li&gt;
&lt;li&gt;“Controller”, “Presenter”, and the “View-Model” are translators that mediate between the views and the model. Other than this, the VIPER pattern contains the “entity” and “router” translator which represents the data and network routing.&lt;/li&gt;
&lt;li&gt;These translators can be quite complex to write, so various patterns have been proposed to make them more maintainable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🤔Self Activity:
&lt;/h2&gt;

&lt;p&gt;Over to you: keep in mind that this is not an exhaustive list of architectural patterns. Other notable patterns include Flux and Redux. How do they compare to the ones mentioned here?👀  &lt;/p&gt;

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

&lt;p&gt;In conclusion, while all of these architectural patterns share some similarities, they each have their own unique characteristics and are best suited for different types of applications. Choosing the right architecture pattern can make a huge difference in the quality and maintainability of the codebase, so it's important to take the time to understand the pros and cons of each pattern before making a decision.&lt;/p&gt;




&lt;p&gt;That's all for today.&lt;/p&gt;

&lt;p&gt;Share your feedback, and if you like it, then kindly retweet the first tweet😀&lt;/p&gt;

&lt;p&gt;New to my profile?🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full stack developer from India. I tweet and document my coding journey🌸&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more such content🔥😉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>architecture</category>
    </item>
    <item>
      <title>API Architectural Styles</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Thu, 23 Mar 2023 17:37:01 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/api-architectural-styles-5348</link>
      <guid>https://dev.to/ayushsoni1010/api-architectural-styles-5348</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What are the API Architectural Styles?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The diagram below shows the common API architectural styles at a glance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wu-NN6Rj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3be20drxg8qw2n1r1gr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wu-NN6Rj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3be20drxg8qw2n1r1gr1.png" alt="API" width="800" height="1013"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🚀Let's take a closer look at the different architectural styles.&lt;/p&gt;

&lt;p&gt;🤔How often do you know what architectural patterns are available?👀&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀&lt;strong&gt;REST:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Proposed in 2000, REST is the most commonly used style. It is often used between frontend clients and backend services. It is compliant with 6 architectural constraints. The common payload formats can be JSON, XML, HTML, or plain text.&lt;/p&gt;

&lt;p&gt;The six architectural constraints are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uniform interface&lt;/li&gt;
&lt;li&gt;Stateless&lt;/li&gt;
&lt;li&gt;Cacheable&lt;/li&gt;
&lt;li&gt;Code on demand&lt;/li&gt;
&lt;li&gt;Layered system&lt;/li&gt;
&lt;li&gt;Client-server&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🚀&lt;strong&gt;GraphQL:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;GraphQL was proposed in 2015 by Meta. It provides a schema-based and type system suitable for complex systems where the relationships between entities are graph-like.&lt;/p&gt;

&lt;p&gt;Let's understand it through the diagram. GraphQL can retrieve user and order information in one request, whereas in REST, it requires multiple calls to get the information for user and order.&lt;/p&gt;

&lt;p&gt;GraphQL is not a replacement for REST. It can be built upon existing REST services.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀&lt;strong&gt;WebSockets:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;WebSockets are a protocol that provides full-duplex communication over TCP. Clients establish WebSockets to receive real-time updates from the backend services.&lt;/p&gt;

&lt;p&gt;Unlike REST, which always pulls data, WebSockets enable pushing.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀&lt;strong&gt;Webhooks:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Webhooks are usually used for third-party asynchronous API calls.&lt;/p&gt;

&lt;p&gt;Let's understand how it works under the hood.&lt;/p&gt;

&lt;p&gt;As shown in the diagram, we use Stripe and PayPal for payment channels and register a Webhook for payment results. When a third-party payment service is done, it notifies the payment service if the payment is successful or failed. Webhook calls are usually part of the system's state machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀&lt;strong&gt;gRPC:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Released in 2016, gRPC is used for communications among microservices. The gRPC library handles encoding/decoding and data transmission.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀SOAP:
&lt;/h3&gt;

&lt;p&gt;SOAP stands for Simple Object Access Protocol. Its payload is XML only, suitable for communications between internal systems.&lt;/p&gt;

&lt;p&gt;🤔Over to you: What API architectural styles have you used?&lt;/p&gt;




&lt;p&gt;Share your feedback, and if you like it, then kindly retweet the first tweet😃&lt;/p&gt;

&lt;p&gt;New to my profile? 🎉&lt;/p&gt;

&lt;p&gt;Hey! I am Ayush, a full-stack developer from India. I tweet about my coding journey.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/ayushsoni1010"&gt;@ayushsoni1010&lt;/a&gt; for more such content😉&lt;/p&gt;

</description>
      <category>api</category>
      <category>graphql</category>
      <category>webdev</category>
      <category>webhook</category>
    </item>
    <item>
      <title>Hacking at MLH HackCon</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Sat, 17 Dec 2022 01:32:25 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/hacking-at-mlh-hackcon-34ak</link>
      <guid>https://dev.to/ayushsoni1010/hacking-at-mlh-hackcon-34ak</guid>
      <description>&lt;p&gt;At the beginning of 2021, I started my developer journey, meeting with such amazing people virtually was by no chance by getting involved and active in the tech communities during pandemics. In the meantime, building skills and collaborating with different people around the world makes me more inclined to tech communities and software products.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀Leveling up with the Hackathons
&lt;/h2&gt;

&lt;p&gt;Hacking in the hackathons and working on the different projects hacks amazed me to love hackathons by &lt;a href="//mlh.io"&gt;Major League Hacking&lt;/a&gt;. Attended the very first hackathon virtually with my team involving @&lt;a href="https://linkedin.com/in/sehgalyash"&gt;Yash Sehgal&lt;/a&gt;, and @&lt;a href="https://www.linkedin.com/in/tanishajain11/"&gt;Tanisha Jain&lt;/a&gt; ranked in the top 11 in the Abracadabra Hacks by MLH. In the initial days of programming, I was a noob, Yash mentored us and we build the amazing hack project in the last minute of the submission period, but we lagged with the submission of the project, though we did a lot of hard work that symbolized us rude and mute. &lt;/p&gt;

&lt;p&gt;After some time, I connected with one of the MLH coaches and had a great conversation with him. With all the efforts and conversations with Stephen from MLH turned our project into the top-ranked list. At this incredible stage, we are so happy that we finally submitted it and the struggle pays it off.&lt;/p&gt;

&lt;h2&gt;
  
  
  🗣️Diving Deep into the Communities
&lt;/h2&gt;

&lt;p&gt;Participating in several hackathons and open-source contribution programs made me so consistent within the open-source and tech communities to build something. In mid-2021, mentored many people related to technology, took sessions, and get involved in many communities by leveling up personal branding. These results made me shine as a Microsoft Learn Student Ambassador. A community leader building various open source and tech communities.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯The journey to HackCon India
&lt;/h2&gt;

&lt;p&gt;Getting so curious to attend my very first tech conference by Major League Hacking Community in Delhi. It’s the first HackCon conference in India organized by MLH. The way to Delhi with my friend &lt;a href="https://linkedin.com/in/sehgalyash"&gt;Yash Sehgal&lt;/a&gt; was really exciting and my first experience in a metro.&lt;/p&gt;

&lt;p&gt;Before the conference, we are full of pre-planned todos. We have visited and explored so many beautiful places like Jantar Mantar, Rajghat, Cannaught Place, Agrasen ki Baoli, etc.&lt;/p&gt;

&lt;p&gt;On the second day, when arriving back at the hotel due to heavy rain, all around us was full of water and the auto-rickshaw gas was going to be empty soon. After some time, we lost the route to the hotel, this moment made us frightened and it was hard to find the route due to the heavy rain. Finally, we struggled to find the way and reached to hotel.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤩It’s the HackCon day
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VFBTwR-e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hoaxlp510yruvkqi05o6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VFBTwR-e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hoaxlp510yruvkqi05o6.png" alt="Image" width="510" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, the wait is over, and heading toward attending HackCon was a full of exciting journey so far. Got to know about so many folks out there and met different people, what they’re doing and hacking these days, taking selfies with the people around us, meeting with the community leaders, GitHub Campus Experts, and to whom I interacted virtually get connected in real life.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P567GSs1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1671239702465/cLIZdeNet.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P567GSs1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1671239702465/cLIZdeNet.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="Image" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go a bit back on how I ended up attending HackCon India. Being joined by around 200 hackers/organizers HackCon started around 8 am with the Keynote session by Mike Swift (CEO of MLH) followed by many other community leaders/builders and hackathon organizers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z5ZJEK2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--FhCo9PGw--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://i.imgur.com/QFdsdxC.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z5ZJEK2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--FhCo9PGw--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://i.imgur.com/QFdsdxC.jpg" alt="image" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub Education being the sponsor of the event conducted various interesting activities and giveaway cool swags, involving polaroid photos, developer badges, stickers, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;🤝Network - Inspire - Collaborate&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;At HackCon, my curiosity level and the way of talking with the folks out there amazed me, and the accent while having the conversation is so fantastic. The conference made me in that state in which my energy for networking with people, learning something new from them, and deeper talks on developer terminology, being a community leader how to lead the community, various techniques and ways to organize hackathons in a pre-planned timeline for a successful event, and learned about different technologies and companies.&lt;/p&gt;

&lt;p&gt;There were amazing workshops by great leaders and planned breakout time to interact with the attendees. This conference inspired me to attend various conferences/events, community building, and keep hacking at amazing hackathons.&lt;/p&gt;

&lt;p&gt;Last but not the least, could not express more about the learnings in words, I learned a lot of things. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 The best way to get help is to make it easier for people to help you.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Happy Hacking💜&lt;/p&gt;

&lt;p&gt;Ayush Soni&lt;/p&gt;

</description>
      <category>mlh</category>
      <category>opensource</category>
      <category>github</category>
      <category>conference</category>
    </item>
    <item>
      <title>Let's Grow with LetsGrowMore ✨</title>
      <dc:creator>Ayush Soni</dc:creator>
      <pubDate>Mon, 20 Sep 2021 09:09:26 +0000</pubDate>
      <link>https://dev.to/ayushsoni1010/let-s-grow-with-letsgrowmore-1db2</link>
      <guid>https://dev.to/ayushsoni1010/let-s-grow-with-letsgrowmore-1db2</guid>
      <description>&lt;p&gt;Learning Web Development is never been an easy task for me until I get some real hands-on experience. It's all started in June 2021, I was exploring an open-source program on google, I was also using LinkedIn for finding such technically experienced people. Suddenly, a post comes into my feed and that was about LetsGrowMore. And, then I was come to know that day LetsGrowMore is not just providing open-source enthusiasts a platform to showcase their skills in a different field but also provides an opportunity to undergraduates to work together with them as an intern in various fields.&lt;br&gt;
I grabbed the opportunity with both hands and applied and thus opening the gateway to the Open Source world!&lt;/p&gt;

&lt;p&gt;So, Now let's talk about What community is this and how they help the beginner to boost their skills. For beginners, I would first like to clear some things. Here we go:&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Open Source🤔?
&lt;/h2&gt;

&lt;p&gt;I think you might’ve studied about this. There are generally two types of software that programmers code a closed source software, and open-source software. open-source software is the one for which the source code is made freely available and may be redistributed and modified. This is done to accept bugs, issues, and other features from around the world helping the open-source software community. So next time when you’re on a website like Github, working on a project (repository), and contributing your code to it, consider yourself to be a lucky person because you’re now an open-source contributor, Open source has become a movement and a way of working that reaches beyond software production. The open-source movement uses the values and decentralized production model of open-source software to find new ways to solve problems in their communities and industries.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is LetsGrowMore🚀?
&lt;/h2&gt;

&lt;p&gt;LetsGrowMore is a ground-based organization that aims at building the future through nourishing the present. LetsGrowMore believes in making our youth especially the students self-aware and exploring the untouched world of technology and tremendous growth-making fields and our belief finally took us where we are standing today. Today LetsGrowMore is an officially MSME registered start-up with nearly 100+ people working under the same establishment.&lt;br&gt;
Well, this is not what LetsGrwMore aims for, their plans are much higher and they are working for it. Soon they are coming with new projects which target the future building.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the main missions of LetsGrowMore🎯?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Help Everyone To Grow&lt;/strong&gt;&lt;br&gt;
Learning is a never-ending process! To make sure everyone will learn new things in the right way LetsGrowMore provides a healthy community where everyone can share.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Provide Learning Opportunity&lt;/strong&gt;&lt;br&gt;
At LetsGrowMore they aim to provide as many opportunities as possible.&lt;br&gt;
For now, they are offering many free opportunities such as :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://letsgrowmore.in/vip"&gt;LGMVIP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://letsgrowmore.in/soc"&gt;LGMSoC'21&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://forms.gle/vi5YgBREv5LQ6CMw9"&gt;LGMWEP(For Girls-Only)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://letsgrowmore.in/vip/"&gt;Web Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://letsgrowmore.in/vip/"&gt;Tech Intern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/forms/d/1kfEcNyxKit0Ib8xV5sU4c4KI2fY9JcK8DvYklfQuOz0/viewform?edit_requested=true"&gt;Campus Ambassador&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/forms/d/1ZnAdbukXaTVj_S0sgn6PfJh1UwKlpX4tuD87mdRhO_8/viewform?edit_requested=true"&gt;Social Media Marketing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/forms/d/12VyIWPh3bmE8SfkhOy7JrYWZjclzCOP_Gp4Tn4zFVZo/viewform?edit_requested=true"&gt;Content Writing Intern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/forms/d/e/1FAIpQLSdXeL_soItd5fFZQByZeQyaceYPbEJoSf5Hx2W9XmAo0_m_sg/viewform?usp=sf_link"&gt;Graphic Designer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Build a better tomorrow&lt;/strong&gt;&lt;br&gt;
By investing in students, they not only providing students a platform, but they also focus on how did students get all the in free of cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Knowledge grows by sharing&lt;/strong&gt;&lt;br&gt;
Creating an educational open-source community will help beginners to build a solid network with more experienced individuals and under their guidance, they can pave their path in the field of development.&lt;/p&gt;

&lt;h2&gt;
  
  
  How this community helps you🛡?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;They enhance your understanding and appreciation of diversity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They provide various services within the community&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They allow members to gain personal and professional skills in the area of leadership &amp;amp; development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can also grow within the community to become a mentor in the organization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They support and encourage students to explore their multiple identities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They provide convenient, up-to-date services to meet the current needs of the community.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They provide leisure learning, continuing education courses for the campus and community.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What I have learned from this program 🧾?
&lt;/h2&gt;

&lt;p&gt;Although I have learned many things but will emphasize some important points here. Having in a huge team is a fantastic experience for me, more than 500+ contributors are working on several projects, invokes teamwork within us which is a very important soft skill a student much have I'm also an introvert before joining this awesome community but after joining I learned many things like how to express my views with others, solving problems, helping new programmers, managing projects. Apart from the art of taking help from others, the art of helping others is also a silent feature of this program.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Please forgive me if I have done any grammatical errors in this article as I’m yet improving my English.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;“If everyone is moving forward together, then success takes care of itself.”&lt;br&gt;
— Henry Ford&lt;/p&gt;

&lt;p&gt;Good luck to everyone who’s about to decide between contributing to this amazing and open world of coders. 🙌&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>letsgrowmore</category>
      <category>lgm</category>
      <category>opensourceprogram</category>
    </item>
  </channel>
</rss>
