<?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: Milan Sachani </title>
    <description>The latest articles on DEV Community by Milan Sachani  (@milan960).</description>
    <link>https://dev.to/milan960</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%2F790380%2F1b96fab2-61f0-4feb-8f5b-fc511666cd5d.jpeg</url>
      <title>DEV Community: Milan Sachani </title>
      <link>https://dev.to/milan960</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/milan960"/>
    <language>en</language>
    <item>
      <title>🔑 Key Habits of Successful Developers</title>
      <dc:creator>Milan Sachani </dc:creator>
      <pubDate>Sun, 14 May 2023 08:07:51 +0000</pubDate>
      <link>https://dev.to/milan960/key-habits-of-successful-developers-3elj</link>
      <guid>https://dev.to/milan960/key-habits-of-successful-developers-3elj</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Continuous Learning:&lt;br&gt;
The tech industry is always evolving. Successful developers make learning new technologies, languages, or tools part of their routine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Problem Solving:&lt;br&gt;
Being a good developer is all about solving problems. It's essential to cultivate strong analytical thinking and problem-solving skills.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understanding the Basics:&lt;br&gt;
Before jumping into frameworks and libraries, make sure you have a solid understanding of the fundamentals (HTML, CSS, and JavaScript for web developers).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code Readability:&lt;br&gt;
Writing code that other humans can understand is just as important as writing code that machines can execute. Use clear naming conventions, keep functions small and focused, and always document your code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collaboration and Communication:&lt;br&gt;
Developers rarely work alone. Being able to work effectively in a team and communicate your ideas clearly is crucial.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing and Debugging:&lt;br&gt;
Learning how to efficiently debug your code and writing tests to prevent bugs is an essential skill.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Embracing Mistakes and Failure:&lt;br&gt;
Don't be afraid to make mistakes - they are an important part of the learning process. Learn from them and move on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building Projects:&lt;br&gt;
The best way to learn and improve as a developer is by building projects. They help consolidate your learning and give you something to show potential employers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Staying Healthy:&lt;br&gt;
Spend time away from the screen. Regular exercise, a good diet, and sufficient sleep are important for everyone, including developers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Joining a Community:&lt;br&gt;
Being part of a developer community can provide support, inspiration, learning opportunities, and even job prospects. Consider joining local meetups, online forums, or contributing to open-source projects.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember, everyone's journey in coding is unique, and success comes in many forms. Keep coding, keep learning, and most importantly, enjoy the process!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering Debounce and Throttle: Improve Your Web Performance with Ease</title>
      <dc:creator>Milan Sachani </dc:creator>
      <pubDate>Fri, 05 May 2023 10:27:13 +0000</pubDate>
      <link>https://dev.to/milan960/mastering-debounce-and-throttle-improve-your-web-performance-with-ease-1p5j</link>
      <guid>https://dev.to/milan960/mastering-debounce-and-throttle-improve-your-web-performance-with-ease-1p5j</guid>
      <description>&lt;p&gt;Get the most out of your web applications by learning when and how to use debounce and throttle functions&lt;/p&gt;

&lt;p&gt;Introduction:&lt;/p&gt;

&lt;p&gt;When building web applications, developers often face a common challenge:&lt;/p&gt;

&lt;p&gt;optimizing the performance of their apps, especially when it comes to handling user interactions. Debouncing and throttling are two powerful techniques used to improve performance by controlling the rate at which events are triggered. In this blog post, we will explore both concepts and provide practical examples to help you understand when and how to implement them in your projects.&lt;/p&gt;

&lt;p&gt;1) Understanding Debounce and Throttle&lt;/p&gt;

&lt;p&gt;Debouncing and throttling are used to limit the number of times a function is called within a specified time frame, reducing the impact of repetitive and rapid user interactions on your application’s performance. Here’s a brief overview of each technique:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Debounce: Delays the execution of a function until a specified amount of time has passed since the last time the function was called. If the function is called again before the time has elapsed, the timer is reset, and the process begins again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Throttle: Ensures that a function is only executed once during a specified time period, regardless of how many times it is called.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2) Real-World Use Cases&lt;br&gt;
Debouncing and throttling are commonly used in the following scenarios:&lt;/p&gt;

&lt;p&gt;Search input: Debounce can improve the search experience by only triggering the search request when the user has stopped typing, reducing unnecessary requests to the server.&lt;/p&gt;

&lt;p&gt;Scroll events: Throttle is useful for handling scroll events, ensuring that the function is not executed too frequently, and improving the performance of features such as infinite scrolling or lazy loading.&lt;/p&gt;

&lt;p&gt;3) Implementing Debounce and Throttle&lt;/p&gt;

&lt;p&gt;Here’s how you can create simple debounce and throttle functions in JavaScript:&lt;/p&gt;

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

&lt;p&gt;4) Practical Examples&lt;/p&gt;

&lt;p&gt;Let’s see how to implement debounce and throttle in real-world scenarios:&lt;/p&gt;

&lt;p&gt;A. Debounce — Search Input&lt;/p&gt;

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

&lt;p&gt;B. Throttle — Scroll Event&lt;/p&gt;

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

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;Debouncing and throttling are essential techniques for optimizing the performance of web applications that handle user interactions. By understanding their differences and how to implement them, you can significantly improve the responsiveness and user experience of your projects. Next time you face performance issues due to repetitive events, consider using debounce or throttle to streamline your app’s behavior!&lt;/p&gt;

&lt;p&gt;Thank you for reading it keep learning!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>How to create a Nodejs server and Add Swagger to a Project 🔥 and deployed on vercel CLI</title>
      <dc:creator>Milan Sachani </dc:creator>
      <pubDate>Thu, 09 Mar 2023 10:45:01 +0000</pubDate>
      <link>https://dev.to/milan960/how-to-create-a-nodejs-server-and-add-swagger-to-a-project-and-deployed-on-vercel-cli-39a8</link>
      <guid>https://dev.to/milan960/how-to-create-a-nodejs-server-and-add-swagger-to-a-project-and-deployed-on-vercel-cli-39a8</guid>
      <description>&lt;p&gt;&lt;strong&gt;OpenApi&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OpenAPI defines some standards which are used;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for the design of RESTful web servers,&lt;/li&gt;
&lt;li&gt;for testing APIs, without accessing source codes,&lt;/li&gt;
&lt;li&gt;for the documenting of APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can inform the users of your APIs with OpenAPI about&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the endpoints&lt;/li&gt;
&lt;li&gt;CRUD operations&lt;/li&gt;
&lt;li&gt;Authentication methods&lt;/li&gt;
&lt;li&gt;Contact information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Swagger&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Swagger is a set of open-source software tools built around the OpenAPI Specification with which we can build, document, and test our APIs.&lt;/p&gt;

&lt;p&gt;You can get more information about Swagger from its web site.&lt;/p&gt;

&lt;p&gt;In this article, I will talk about;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how to implement Swagger to a RESTful web server built with Node.js&lt;/li&gt;
&lt;li&gt;Swagger UI&lt;/li&gt;
&lt;li&gt;API Documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will go on to tell assuming that you are familiar with Node.js and RESTful API concepts at least at a basic level that I will use VS Code as the code editor.&lt;/p&gt;

&lt;p&gt;Firstly let’s create a RESTful web server:&lt;/p&gt;

&lt;p&gt;Navigate the cursor to the file and create the project in the terminal. here we will create the package.json file with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init --y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since I won’t use a database in the project, let’s create fake data. For that, I am creating a file called data.js and adding an array that consists of some info in JSON format. The scenario of the fake data is that some authors and their posts.&lt;/p&gt;

&lt;p&gt;data.js file&lt;/p&gt;

&lt;p&gt;Now let’s add the packages that are necessary to create the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express cors morgan body-parser dotenv
For the convenience of Syntax;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;i) let’s add the babel modules to the project:&lt;/p&gt;

&lt;p&gt;npm install &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/core &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/node &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env&lt;br&gt;
ii) let’s create the .babelrc file and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “presets”: [“@babel/preset-env”]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, let’s add the following code to the scripts field in the package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“start”: “nodemon — exec babel-node src/index.js”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don’t have nodemon on your PC, I advise installing it globally.&lt;/p&gt;

&lt;p&gt;And then let’s create the src/index.js file and add the following codes:&lt;/p&gt;

&lt;p&gt;As you can see, we will reach the posts.js file which includes the APIs, from the index.js file with the /posts endpoint.&lt;/p&gt;

&lt;p&gt;Now let’s create the posts.js file and add to it CRUD operations:&lt;/p&gt;

&lt;p&gt;The posts.js file&lt;br&gt;
In the last case, the project files should look like this:&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%2Fwjw48yt2q01mkn7sf8pt.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%2Fwjw48yt2q01mkn7sf8pt.png" alt="Image description folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a RESTful web service that runs on the 2000 port. You can run it simply with the npm start command. You can test the CRUD operations with Postman.&lt;/p&gt;

&lt;p&gt;Maybe you find it a little complicated that test APIs with Postman. Here Swagger comes into play.&lt;/p&gt;

&lt;p&gt;Adding Swagger to the project&lt;br&gt;
Firstly, let’s install two modules that are necessary for documentation and user interface (UI):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install swagger-jsdoc swagger-ui-express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I am importing these two modules in the index.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import swaggerUI from “swagger-ui-express”;
import swaggerJsDoc from “swagger-jsdoc”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, in index.js let’s make some necessary definitions for the documentation of APIs and implementation of Swagger UI:&lt;/p&gt;

&lt;p&gt;The options variable is an OpenAPI object. It is possible to give some information regarding APIs with this (title, version information, contact information, etc.).&lt;/p&gt;

&lt;p&gt;For more information, you can check this link.&lt;/p&gt;

&lt;p&gt;And we see that implementation is possible only with one single-line code.&lt;/p&gt;

&lt;p&gt;It will be more clear when we see the definitions under the definition field on the display. Note that the server URL and APIs are specified in the options variable.&lt;/p&gt;

&lt;p&gt;Now we can display Swagger UI with /api-docs endpoint after we run the server:&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%2Fgmaenfs1g179xw2pewqj.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%2Fgmaenfs1g179xw2pewqj.png" alt="Image description swaggerui"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now we can make the specifications that will display and run our APIs that are in the src/Routes/posts.js file on the Swagger screen. We used the JSON format to define the options variable in the index.js file. But we will use the YAML format for schema definitions. (It is possible to use both formats).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am beginning by defining the Components Object. This object is defined to be used in various parts of the documentation. We can say that is a schema of the data we will use. Unless it won’t be called by any property of documentation, it has no effect on APIs.&lt;/p&gt;

&lt;p&gt;For more information about how to add more properties to Components Object, you can check this &lt;a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tags&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the Tags feature of Swagger, we can create a list of Tags with which we can distinguish which function on Swagger UI belongs to which data. Since we have APIs that belong just to the Posts data, there won’t be confusion about API functions. But in the documentation that includes APIs related to multiple data, Tags are inevitable.&lt;/p&gt;

&lt;p&gt;Let’s try to understand the Tag issue better with a screenshot from another RESTful API documentation:&lt;/p&gt;

&lt;p&gt;PS: I do not have all the tags as I am still implementing however here is some sample example.&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%2Fbw8p963eqck2sagmyjnp.jpeg" 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%2Fbw8p963eqck2sagmyjnp.jpeg" alt="Image description tag"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our user interface (UI) looks like this yet:&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%2F0uohn6571omhp03dh8lb.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%2F0uohn6571omhp03dh8lb.png" alt="Image description tagnot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Documentation of HTTP Methods:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GET Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s get started with the documentation of the GET operation:&lt;/p&gt;

&lt;p&gt;If you need to talk about, first we specified the endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/posts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we added a description and specified to which tag it belongs. Then we added responses information.&lt;/p&gt;

&lt;p&gt;For more information on the documentation of HTTP Methods, you can check this &lt;a href="https://swagger.io/docs/specification/paths-and-operations/" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more information on the responses object, you can check this &lt;a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responses-object" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will see that the &lt;em&gt;GET&lt;/em&gt; function has been added to the Posts Tag on Swagger UI:&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%2F1p7pi76omdg2qaif42fk.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%2F1p7pi76omdg2qaif42fk.png" alt="Image description POSTUI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GET Method with parameter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s make the documentation of the function that calls a single post by the id:&lt;/p&gt;

&lt;p&gt;Note that unlike the previous one, the id is added to the path as /posts / {id}. Since we now need a parameter in the function to be able to call a post by its id, a parameters object has been added to the documentation. Since we have chosen the “adding the parameter to the path” method while accessing the API, the following statement is included under the parameters field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-in : path
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is also possible to do this in different ways.&lt;/p&gt;

&lt;p&gt;For more information on the parameters object, you can check this link.&lt;/p&gt;

&lt;p&gt;The GET method that calls data by the id parameter will look like this in the interface:&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%2Fvikmyx8gm0c427gc6lqw.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%2Fvikmyx8gm0c427gc6lqw.png" alt="Image description get"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;POST Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s make the documentation of the POST method that add a new post to current data:&lt;/p&gt;

&lt;p&gt;With the above documentation, the POST button (green one) shown below will be added in the Swagger interface:&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%2F26hvap83qple87gqt7xq.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%2F26hvap83qple87gqt7xq.png" alt="Image description posts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the documentation, we will see the requestBody field, unlike the others. This provides us an area in which we can create a new post in the POST function in the Swagger UI. This area will open when the Try it out button is clicked. An example post object in the schema we defined at the beginning comes as default in this area. Fields can be changed on the example if desired.&lt;/p&gt;

&lt;p&gt;For more information about requestBody, you can check &lt;a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responses-object" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PUT Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As it is known, in the RESTful approach, existing datas are updated with the PUT function. For this, the id of the data to be updated is usually required. Therefore, we add a parameter field to the documentation of the PUT function and the expression {id} right after the / post endpoint. To update the properties of the data captured with its parameter, we add requestBody as in the POST function. We add the 404 response to the responses section for the case of the absence of data belonging to the entered id information:&lt;/p&gt;

&lt;p&gt;The put operation on the Swagger display will look like this:&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%2Fuzbj3jrzz6i8ub6icxou.jpeg" 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%2Fuzbj3jrzz6i8ub6icxou.jpeg" alt="Image description put"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DELETE Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is usually sufficient to give only one id to the function to delete data. We do so too. For this, we add the parameter field and the responses field that will show us the responses, to the documentation:&lt;/p&gt;

&lt;p&gt;The delete operation on the Swagger display will look like this:&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%2Fctrajap4138xslmccllh.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%2Fctrajap4138xslmccllh.png" alt="Image description delete"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we talked about how to document RESTful APIs in a web server created in Node.js with the OpenAPI approach. We talked about which setting-ups can be made to view this documentation on the Swagger UI. We created a model project together.&lt;/p&gt;

&lt;p&gt;You can access this project from the following &lt;a href="https://github.com/Milan-960/Nodejs-swagger-api" rel="noopener noreferrer"&gt;Github link&lt;/a&gt;. and deployed version as well :&lt;a href="https://nodejs-swagger-api.vercel.app/" rel="noopener noreferrer"&gt;Nodejs-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can connect with me here! &lt;br&gt;
&lt;a href="https://www.linkedin.com/in/milan-sachani-9090/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading it keep learning! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>node</category>
    </item>
  </channel>
</rss>
