<?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: Cássio Santiago Cappellari</title>
    <description>The latest articles on DEV Community by Cássio Santiago Cappellari (@cassiocappellari).</description>
    <link>https://dev.to/cassiocappellari</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%2F565847%2Fb0fbaa12-3bca-4788-b45d-f0700bb8845d.jpg</url>
      <title>DEV Community: Cássio Santiago Cappellari</title>
      <link>https://dev.to/cassiocappellari</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cassiocappellari"/>
    <language>en</language>
    <item>
      <title>Basic Concepts of Node.js</title>
      <dc:creator>Cássio Santiago Cappellari</dc:creator>
      <pubDate>Wed, 25 Aug 2021 11:50:42 +0000</pubDate>
      <link>https://dev.to/cassiocappellari/basic-concepts-of-node-js-pch</link>
      <guid>https://dev.to/cassiocappellari/basic-concepts-of-node-js-pch</guid>
      <description>&lt;h2&gt;
  
  
  🔶 Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine a web application that sends hundreds of requests per second to a server that only processes one request per time before moving to another request. Probably you will have some performance issues and will provide a bad experience to your users.&lt;/p&gt;

&lt;p&gt;With this context in mind, Node.js was created in 2009 by Ryan Dahl, a web developer, after he faced some difficult issues by developing features with intense input and output flow using synchronous programming and multi-threaded server-side platforms.&lt;/p&gt;

&lt;p&gt;Therefore, &lt;strong&gt;Node.js was a technology built to solve a specific problem: deal with intense asynchronous input and output events&lt;/strong&gt;. And, which programming language has this capacity? The answer was: JavaScript.&lt;/p&gt;

&lt;p&gt;So, in this article, I share my knowledge, experience and studies about this technology, with the main goal to provide the basic concepts of Node.js, and help you to understand why it’s such an important player in a modern server-side world.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 1 What is Node.js?
&lt;/h2&gt;

&lt;p&gt;In simple terms, &lt;strong&gt;Node.js is an open-source JavaScript based platform for server-side programming built on Chrome's V8 JavaScript engine&lt;/strong&gt;, which means that the engine that compiles JavaScript in a web Browser it's the same engine that runs Node.js in it’s core, and that's what makes it so fast, especially for web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 2 Why Node.js?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Node.js is an extremely powerful server-side platform to develop modern, reliable and scalable web applications&lt;/strong&gt;, trusted by global companies such as Netflix, Uber, LinkedIn and PayPal.&lt;/p&gt;

&lt;p&gt;Due to its single thread characteristics combined with a multi thread platform that runs in background, &lt;strong&gt;it’s event driven architecture is perfect for applications with intense I/O (Inputs and Outputs)&lt;/strong&gt;, making it serve more clients with less hardware, which means more performance with less costs.&lt;/p&gt;

&lt;p&gt;Besides that, this platform provides other amazing features for developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fx1km68oj19u8otbknnqk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fx1km68oj19u8otbknnqk.jpg" alt="Node.js Advantages" width="800" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.1 Non-Blocking I/O
&lt;/h3&gt;

&lt;p&gt;Non-blocking method receives an input and returns the output asynchronously. In other words, &lt;strong&gt;it makes it possible for a server to receive many requests without blocking the application while the response is being processed in the background&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.2 Single Thread
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Node.js can deal with many events at the same time with its single thread characteristic that delegates the asynchronous operations to a multi thread platform&lt;/strong&gt;, which means that &lt;strong&gt;just one thread is able to handle inputs and outputs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This feature makes it lightweight, scalable and efficient by consuming low memory and infrastructure capacity in order to process a huge number of requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.3 Event Driven
&lt;/h3&gt;

&lt;p&gt;Node.js is an event driven technology, which means that &lt;strong&gt;the control flow of this server side platform is driven by the occurrence of events&lt;/strong&gt;. So, at the moment that a Node application starts, an event listener called Event Loop begins to wait for events and doesn't stop until the application is shutting down.&lt;/p&gt;

&lt;p&gt;In other words, it’s like having a really efficient waiter waiting for orders until the restaurant closes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fezpocyug0okbj7dodf50.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fezpocyug0okbj7dodf50.jpg" alt="Node.js Event Driven" width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.4 Node Package Manager
&lt;/h3&gt;

&lt;p&gt;Node Package Manager it’s &lt;strong&gt;the world's largest free and open source library of functionalities, and can be easily imported and used in any Node application&lt;/strong&gt;. All this means that, regardless of the tools that an application needs, it will be found at Node Package Manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.5 No Buffering
&lt;/h3&gt;

&lt;p&gt;Node.js applications never buffer data, which dramatically reduces the processing time of uploading files, such as videos or audios. In other words, it &lt;strong&gt;simply outputs data in chunks&lt;/strong&gt;, meaning that, for example, a user can watch videos without any interruption.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.6 Scalable
&lt;/h3&gt;

&lt;p&gt;Scalability is a core Node characteristic, due to a &lt;strong&gt;high capacity of handling large amounts of requests asynchronously with low infrastructure&lt;/strong&gt; by it’s architecture that operates on single thread combined with multi thread platform, allowing it receives thousands of simultaneous events.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 3 Node.js Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Node.js architecture has 3 key elements that work together like an event processing factory&lt;/strong&gt;. So, in order to make it easier to understand how these elements interact with each other, I will give an example of a REST API developed in Node.js.&lt;/p&gt;

&lt;p&gt;Let’s say that a Client sends several requests to this application:&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.1 Event Queue
&lt;/h3&gt;

&lt;p&gt;1- As soon as these requests reach the application, they go to the Event Queue, which is a &lt;strong&gt;queue where all the events that occur in the application goes first&lt;/strong&gt;, and where they await to be sent to be processed in the main thread called Event Loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.2 Event Loop
&lt;/h3&gt;

&lt;p&gt;2- When a request (Blocking Operation) enters in the Event Loop, which is a &lt;strong&gt;single thread platform that runs the V8 Engine in its core to compile JavaScript&lt;/strong&gt;, it’s delegated to the Thread Pool platform to be processed in background. So, with this architectural flow, the main thread is available again to handle other events.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.3 Thread Pool
&lt;/h3&gt;

&lt;p&gt;3- In the Thread Pool, which is a &lt;strong&gt;multi thread platform that runs a library called libuv and has C++ in its core&lt;/strong&gt;, the request (Blocking Operation) is processed asynchronously in the background until it’s completed and ready to be returned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvkhqcx31nngbl2kfuj1s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvkhqcx31nngbl2kfuj1s.jpg" alt="Node.js Architecture" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;I hope that this brief article helped you to have a better understanding of not just how Node.js works, but also why it’s a platform that has grown quickly and it's used in so many companies and startups nowadays.&lt;/p&gt;

&lt;p&gt;In a modern and ultra-connected world, a technology that is able to scale fast with low infrastructure for sure it’s an important player to pay attention to.&lt;/p&gt;

&lt;p&gt;So, if you arrived here, &lt;strong&gt;I invite you to read my another article about the fundamentals of tools that are also essential in the web world that we live in: API, REST and HTTP Protocol.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/cassiocappellari/fundamentals-of-rest-api-2nag"&gt;Fundamentals of REST API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written with 💙 by Cássio Cappellari!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>node</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Fundamentals of REST API</title>
      <dc:creator>Cássio Santiago Cappellari</dc:creator>
      <pubDate>Tue, 03 Aug 2021 10:19:21 +0000</pubDate>
      <link>https://dev.to/cassiocappellari/fundamentals-of-rest-api-2nag</link>
      <guid>https://dev.to/cassiocappellari/fundamentals-of-rest-api-2nag</guid>
      <description>&lt;h2&gt;
  
  
  🔶 Introduction
&lt;/h2&gt;

&lt;p&gt;We live in a modern and ultra-connected world that shares a huge amount of data every second through browsers, servers, softwares and applications. For all these systems to communicate with each other, we have a tool that is the key player to integrate all this complexity: the APIs.&lt;/p&gt;

&lt;p&gt;In this article I share my knowledge, experience and studies about this technology, with the goal to provide a basic understanding of the main fundamentals of API, REST and HTTP Protocol.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 1 API Concept
&lt;/h2&gt;

&lt;p&gt;API means &lt;strong&gt;A&lt;/strong&gt;pplication &lt;strong&gt;P&lt;/strong&gt;rogramming &lt;strong&gt;I&lt;/strong&gt;nterface and, like any other interface, allows interactions. In the case of an API, &lt;strong&gt;it allows interactions between systems by following a set of standards and protocols in order to share features, information and data&lt;/strong&gt;. In other words, it provides developers the opportunity to build and design products and services that will communicate with other products and services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F166vtvjvmwbvgxmrz2ta.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F166vtvjvmwbvgxmrz2ta.jpg" alt="API Concept" width="800" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can have different architectural styles of APIs and, nowadays, the main one that is a key part of our Internet world it’s called REST, an acronym for &lt;strong&gt;RE&lt;/strong&gt;presentational &lt;strong&gt;S&lt;/strong&gt;tate &lt;strong&gt;T&lt;/strong&gt;ransfer.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 2 REST Fundamentals
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;REST is an architecture style to develop web services, which uses the HTTP protocol as a communication interface in order to transfer data through HTTP methods.&lt;/strong&gt; In other words, it allows performing basic data manipulation within an application with efficiency, such as creating, retrieving, updating and deleting information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fsz480n8p0ydcq1vsahk3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsz480n8p0ydcq1vsahk3.jpg" alt="REST API" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;REST was born and created in 2000 by Roy Fielding in his PhD dissertation and, according to him:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“The name “Representational State Transfer” is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through the application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, as Roy Fielding defines, in order to build a well-designed web application, we can use REST principles that help us to develop services that are more scalable, reliable and flexible. To achieve this goal, &lt;strong&gt;the REST architecture has six constraints and an API that is driven by that can be called RESTful&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.1 Client-Server
&lt;/h3&gt;

&lt;p&gt;The main principle of the Client-Server web architecture is the Separation of Concerns, which means that the &lt;strong&gt;Client that sends the request it’s completely independent from the Server that returns the response&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdbjyai40l64rfj2yowhp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdbjyai40l64rfj2yowhp.jpg" alt="Client-Server Constraint" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.2 Stateless
&lt;/h3&gt;

&lt;p&gt;All the information (state) that is required in a request must be sended by the Client. Therefore, the Server must not store any data during a Client-Server communication, which means that &lt;strong&gt;every request is a standalone request&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.3 Cache
&lt;/h3&gt;

&lt;p&gt;Cache is a computational storage structure focused on keeping stored data that is frequently accessed, improving performance and network efficiency. Therefore, &lt;strong&gt;through caching, it’s possible to reduce or even eliminate the need for the Client to send requests to the Server (who must inform if the request can be cacheable or not)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.4 Interface Uniform
&lt;/h3&gt;

&lt;p&gt;Means how Client and Server will share information by defining an interface that must be followed in every request. In other words, &lt;strong&gt;it’s a contract between the Client and the Server that determines the standards for their communication&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here, we have four additional constraints that is part of Uniform Interface:&lt;/p&gt;

&lt;h4&gt;
  
  
  2.4.1 Identification of Resources
&lt;/h4&gt;

&lt;p&gt;REST is based on resources, and a resource is an information that can be named. &lt;strong&gt;It’s used in a request to identify what the Client wants to access in the Server&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, to retrieve a list of &lt;code&gt;products&lt;/code&gt;, the resource must be setted in the URL: &lt;code&gt;http://api.example.com/products&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2.4.2 Manipulation of Resources Through Representation
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;The Client must be sure that the request to the Server has enough information to manipulate (create, retrieve, update, delete) the informed resource, which can be represented by multiple formats, such as JSON, XML, HTML etc&lt;/strong&gt;. In other words, the Client can specify the desired representation of a resource in every request to a Server.&lt;/p&gt;

&lt;p&gt;For example: a Client can specify in a request to retrieve a resource in JSON format.&lt;/p&gt;

&lt;h4&gt;
  
  
  2.4.3 Self-descriptive Messages
&lt;/h4&gt;

&lt;p&gt;A self-descriptive message &lt;strong&gt;ensures a uniform interface in the communication by containing all the information that a Client or a Server needs&lt;/strong&gt; to understand the request and the response just by checking the semantics of the message.&lt;/p&gt;

&lt;h4&gt;
  
  
  2.4.4 HATEOAS (Hypertext As The Engine Of Application State)
&lt;/h4&gt;

&lt;p&gt;HATEOAS means that a &lt;strong&gt;response sent from the Server should contain information about what the Client can do in further requests.&lt;/strong&gt; In other words, the Server indicates what actions the Client can do next. In REST standards, Servers must send only hypermedia (links) to Clients.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.5 Layered system
&lt;/h3&gt;

&lt;p&gt;Layered system &lt;strong&gt;relates to the fact that there can be more components and subsystems between a Client and a Server.&lt;/strong&gt; In other words, the client can’t assume that it is communicating directly to the Server, and don’t know about the complexity to process the request and return the response.&lt;/p&gt;

&lt;p&gt;For example: a Client sends a request to a Server, but first it passes by a proxy layer for security check.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F04xp96134kt5cncsmqum.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F04xp96134kt5cncsmqum.jpg" alt="Layered System Constraint" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 2.6 Code On Demand
&lt;/h3&gt;

&lt;p&gt;Code On Demand is the only optional constraint, and &lt;strong&gt;means that a Server can send an executable code as a response to the Client&lt;/strong&gt;. In other words, it’s what happens when a browser, for example, receives a response from the Server with a HTML tag &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; so, when the HTML document is loaded, the script can be executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 3 Request Anatomy
&lt;/h2&gt;

&lt;p&gt;Basically, &lt;strong&gt;a Client request has 4 main elements that compose all the information that is needed to interact with the Server&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.1 URL
&lt;/h3&gt;

&lt;p&gt;URL means &lt;strong&gt;U&lt;/strong&gt;niform &lt;strong&gt;R&lt;/strong&gt;esource &lt;strong&gt;L&lt;/strong&gt;ocator, which &lt;strong&gt;is the address to not just identify a resource, but also to specify how to access it.&lt;/strong&gt; In an API, the URL can be named as Base URL, which means that is the base address that will be used in every request.&lt;/p&gt;

&lt;p&gt;For example: &lt;code&gt;http://api.example.com&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.2 URI
&lt;/h3&gt;

&lt;p&gt;URI means &lt;strong&gt;U&lt;/strong&gt;niform &lt;strong&gt;R&lt;/strong&gt;esource &lt;strong&gt;I&lt;/strong&gt;dentifier, which is used in the URL to &lt;strong&gt;specify which resource the Client would like to access in a request&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example: &lt;code&gt;http://api.example.com/products&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;URL: &lt;code&gt;http://api.example.com/&lt;/code&gt;&lt;br&gt;
URI: &lt;code&gt;/products&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Therefore, every URL is an URI, but not all URIs are URLs.&lt;/p&gt;
&lt;h3&gt;
  
  
  🔸 3.3 Parameters
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Parameters are information that can be sended in a request by the Client in order to influence the response by the Server&lt;/strong&gt;. REST has 4 types of parameters, and its use will depend on the type of action that the request demands.&lt;/p&gt;
&lt;h3&gt;
  
  
  🔸 3.4 Body Params
&lt;/h3&gt;

&lt;p&gt;The Body, like the name says, it’s the &lt;strong&gt;body of the request which contains all the data that the Server needs to successfully process the request.&lt;/strong&gt; Therefore, it’s only used in requests that must send information, such as create or update.&lt;/p&gt;

&lt;p&gt;Example of a request body in JSON format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    “name”: “Laptop”,
    “price”: 1000
    “available”: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔸 3.5 Route Params
&lt;/h3&gt;

&lt;p&gt;Route params are &lt;strong&gt;parameters inserted in the URL with the information to identify a specific resource&lt;/strong&gt; in order to take an action, such as: retrieve, edit, update or delete.&lt;/p&gt;

&lt;p&gt;For example: &lt;code&gt;http://api.example.com/products/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this given example, the route param with value 1 identifies the resource that will be manipulated in the request.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.6 Query Params
&lt;/h3&gt;

&lt;p&gt;Query params are also &lt;strong&gt;parameters inserted in the URL, but with the main difference that it’s use cases are related to filter and search information about a resource, or even paginate and ordinate the results&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;http://api.example.com/products?name=laptop&amp;amp;available=true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this given example, the Client communicates to the Server that the request is to retrieve products with name equals laptop, and available equals true.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 3.7 Headers
&lt;/h3&gt;

&lt;p&gt;Headers &lt;strong&gt;allows sending extra information in a request&lt;/strong&gt;, such as authentication tokens and content types.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Authorization: Bearer token
Accept: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this given example, the Client is sending extra data informing not just it's credentials to access a resource, but also a desired response format.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔶 4 HTTP PROTOCOL
&lt;/h2&gt;

&lt;p&gt;Alright, now that we have a basic understanding of REST fundamentals and it’s constraints, let’s talk about &lt;strong&gt;the communication standard that rules the Internet world by defining  the interaction patterns between Clients and Servers&lt;/strong&gt;: the &lt;strong&gt;HTTP Protocol&lt;/strong&gt; (&lt;strong&gt;H&lt;/strong&gt;yperText &lt;strong&gt;T&lt;/strong&gt;ransfer &lt;strong&gt;P&lt;/strong&gt;rotocol).&lt;/p&gt;

&lt;p&gt;The HTTP Protocol determines not just the methods that are allowed in a REST API, which means the action types that the Client can demand in a request, but also the status codes that the Server returns as a response in order to have a good communication flow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkslln5h0fmx3mngv1dw1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkslln5h0fmx3mngv1dw1.jpg" alt="HTTP Protocol" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 4.1 HTTP Methods
&lt;/h3&gt;

&lt;p&gt;There are &lt;strong&gt;5 main methods that a Client can use in a request in order to manipulate an API resource&lt;/strong&gt;, which are related with the 5 basic data manipulation types in a database, such: Create, Retrieve, Update and Delete.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1.1 GET
&lt;/h4&gt;

&lt;p&gt;This &lt;strong&gt;method is used to retrieve data from a Server&lt;/strong&gt; by indicating the resource in the URL. For example, to request a list of products of an API, the Client might send:&lt;/p&gt;

&lt;p&gt;GET &lt;code&gt;http://api.example.com/products&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1.2 POST
&lt;/h4&gt;

&lt;p&gt;This &lt;strong&gt;method is used to create a new resource in the Server&lt;/strong&gt; by indicating it in the URL and sending the resource data in the request body.&lt;/p&gt;

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

&lt;p&gt;POST &lt;code&gt;http://api.example.com/products&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Request body in JSON format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    “name”: “Laptop II”,
    “price”: 1000
    “available”: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this given example, a new product will be created in the database with this provided information.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1.3 PUT
&lt;/h4&gt;

&lt;p&gt;This &lt;strong&gt;method is used to update a resource data in the Server&lt;/strong&gt; by identifying it in the URL, and sending the information that will be updated in the request body.&lt;/p&gt;

&lt;p&gt;PUT &lt;code&gt;http://api.example.com/products/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Request body in JSON format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    “name”: “Laptop”,
    “price”: 5000,
    “available”: false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this given example, the product with ID 1 will be updated.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1.4 PATCH
&lt;/h4&gt;

&lt;p&gt;This &lt;strong&gt;method is also used to update a resource data in the Server&lt;/strong&gt; by identifying it in the URL, but with the main &lt;strong&gt;difference of updating just a specific information&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;PATCH &lt;code&gt;http://api.example.com/products/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Request body in JSON format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    “available”: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this given example, just the &lt;code&gt;available&lt;/code&gt; property of the product with ID 1 will be updated.&lt;/p&gt;

&lt;h4&gt;
  
  
  4.1.5 DELETE
&lt;/h4&gt;

&lt;p&gt;This &lt;strong&gt;method is used to delete a resource in the Server&lt;/strong&gt; by identifying it in the URL.&lt;/p&gt;

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

&lt;p&gt;DELETE &lt;code&gt;http://api.example.com/products/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this given example, the product with ID 1 will be deleted.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔸 4.2 HTTP Status Code
&lt;/h3&gt;

&lt;p&gt;The HTTP Status Codes &lt;strong&gt;are codes returned by the Server in order to indicate the type of response in a Client’s request&lt;/strong&gt;, facilitating the understanding just by its group and number. &lt;/p&gt;

&lt;p&gt;The most commonly used groups and numbers of status code are:&lt;/p&gt;

&lt;h4&gt;
  
  
  4.2.1 Group 2
&lt;/h4&gt;

&lt;p&gt;Status group that &lt;strong&gt;indicates a successful request&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;200 (Ok)&lt;/th&gt;
&lt;th&gt;201 (Created)&lt;/th&gt;
&lt;th&gt;204 (No Content)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;Request succeeded&lt;/td&gt;
&lt;td&gt;Request succeeded and created resource&lt;/td&gt;
&lt;td&gt;Request succeeded and no additional content in response body&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  4.2.2 Group 3
&lt;/h4&gt;

&lt;p&gt;Status group that &lt;strong&gt;indicates redirect responses&lt;/strong&gt;, which are used to inform the Client that the Server needed to perform a redirect to a new URL.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;301 (Moved Permanently)&lt;/th&gt;
&lt;th&gt;304 (Not Modified)&lt;/th&gt;
&lt;th&gt;307 (Temporary redirect)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;Requested resource has changed permanently and a new URL is provided in the response&lt;/td&gt;
&lt;td&gt;Requested resource wasn’t modified and the same cached version can be used&lt;/td&gt;
&lt;td&gt;Requested resource has been temporarily redirected to another URL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  4.2.3 Group 4
&lt;/h4&gt;

&lt;p&gt;Status group that &lt;strong&gt;indicates an error in the Client side&lt;/strong&gt;, which means that the request was incorrectly builded.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;400 (Bad Request)&lt;/th&gt;
&lt;th&gt;401 (Unauthorized)&lt;/th&gt;
&lt;th&gt;403 (Forbidden)&lt;/th&gt;
&lt;th&gt;404 (Not Found)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;Request couldn’t be understanded by the Server&lt;/td&gt;
&lt;td&gt;Client is not authenticated to access the resource&lt;/td&gt;
&lt;td&gt;Client is not authorized to access the resource&lt;/td&gt;
&lt;td&gt;Requested resource couldn’t be found by the Server&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  4.2.4 Group 5
&lt;/h4&gt;

&lt;p&gt;Status group that &lt;strong&gt;indicates an error in the Server side&lt;/strong&gt;, which means that the request was sent correctly by the Client, but an error occurred while processing it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;500 (Internal Server Error)&lt;/th&gt;
&lt;th&gt;503 (Service Unavailable)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;Indicates that the Server faced an unexpected error, and couldn't return the request response&lt;/td&gt;
&lt;td&gt;Indicates that the Server isn’t able to process the request because it’s unavailable, overloaded or under maintenance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;p&gt;I hope that this article helped you to have a basic theoretical approach about REST fundamentals, which is an essential knowledge to every programmer that develops web services.&lt;/p&gt;

&lt;p&gt;And, now that you have this core understanding, &lt;strong&gt;I invite you to read my other article that provides the basic concepts of an incredible technology for building REST APIs&lt;/strong&gt; just by clicking on the link below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/cassiocappellari/basic-concepts-of-node-js-pch"&gt;Basic Concepts of Node.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written with 💙 by Cássio Cappellari!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
      <category>rest</category>
      <category>api</category>
    </item>
  </channel>
</rss>
