<?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: Gabriel Babler</title>
    <description>The latest articles on DEV Community by Gabriel Babler (@gabrielbabler).</description>
    <link>https://dev.to/gabrielbabler</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%2F676491%2F7d20feb6-c918-439b-a9b8-f4f2b2e6354e.jpeg</url>
      <title>DEV Community: Gabriel Babler</title>
      <link>https://dev.to/gabrielbabler</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gabrielbabler"/>
    <language>en</language>
    <item>
      <title>What is an INTERFACE in JAVA? w/ examples</title>
      <dc:creator>Gabriel Babler</dc:creator>
      <pubDate>Fri, 27 Jan 2023 00:08:01 +0000</pubDate>
      <link>https://dev.to/gabrielbabler/what-is-an-interface-in-java-w-examples-5d9h</link>
      <guid>https://dev.to/gabrielbabler/what-is-an-interface-in-java-w-examples-5d9h</guid>
      <description>&lt;p&gt;Hey folks! In today's post, I would like to talk a little bit about INTERFACES in Java. Let's go?&lt;/p&gt;

&lt;p&gt;So, trying to be as basic as possible, we can start by saying that an &lt;em&gt;interface&lt;/em&gt; it's nothing else than a &lt;strong&gt;contract&lt;/strong&gt;.&lt;br&gt;
That's it! &lt;br&gt;
Do you know when you are opening a new bank account? Or, when you are signing your new rent house? What are they? Contracts! &lt;/p&gt;

&lt;p&gt;Basically, they are pre-defined conditions that you need to accept if you want to use them. Do you think it makes sense?&lt;/p&gt;

&lt;p&gt;Taking that to the programming world, when we define a new interface and add on it some methods, for example:&lt;/p&gt;

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

&lt;p&gt;Here, I am saying that, in case anyone wants to use the interface Bank, the class is forced to implement the methods &lt;em&gt;withdrawn&lt;/em&gt; and &lt;em&gt;deposit&lt;/em&gt;, for example:&lt;/p&gt;

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

&lt;p&gt;For the &lt;em&gt;BankA&lt;/em&gt; to be able to implement the interface &lt;em&gt;Bank&lt;/em&gt;, it needs to implement the methods from Bank and add your own logic to them. Otherwise, Java will complain.&lt;/p&gt;

&lt;p&gt;Also, you can notice the annotation &lt;em&gt;@Override&lt;/em&gt;. In Java, that's the way to implement the methods from the interface.&lt;/p&gt;

&lt;p&gt;Another good thing about the interfaces is they allow us to use polymorphism in Java, where I can use the reference of the interface for every class that implemented it. &lt;br&gt;
Plus, it follows one of the S.O.L.I.D principles - the letter &lt;strong&gt;O&lt;/strong&gt; which stands for &lt;strong&gt;Open-Closed Principle&lt;/strong&gt;. That means the class should be open for extension and closed to modification.&lt;/p&gt;

&lt;p&gt;First, let's see a bad example:&lt;/p&gt;

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

&lt;p&gt;Here we can notice how hard it will be to extend the class if we need to implement new banks to our application, right? Every time I'll have to add a new dependency to my BankService class and implement a new method. &lt;br&gt;
How can we avoid it? &lt;strong&gt;Interfaces&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Look at this:&lt;/p&gt;

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

&lt;p&gt;The code is doing exactly the same thing, but now it's easy to extend the code. I just need to pass the &lt;strong&gt;implementation&lt;/strong&gt; I want to use:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q6Icoj9w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0j0u7eaty1la6w0twn9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q6Icoj9w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0j0u7eaty1la6w0twn9o.png" alt="Image description" width="437" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I create a new instance of BankService I pass as an argument the implementation I want to use, in this case, BankA. And, if I need to implement a new bank, it's as just simple:&lt;/p&gt;

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

&lt;p&gt;And then use it:&lt;/p&gt;

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

&lt;p&gt;Pretty simple, don't you think?&lt;/p&gt;

&lt;p&gt;That's it for today, folks! I hope this article can help you to better understand the interfaces and how to use them to write better code =)&lt;/p&gt;

&lt;p&gt;If you have any questions or suggestions, feel free to leave a comment =)&lt;/p&gt;

&lt;p&gt;See you next time.&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>interfaces</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>ArrayList vs HashSet vs HashMap - The main differences</title>
      <dc:creator>Gabriel Babler</dc:creator>
      <pubDate>Mon, 17 Oct 2022 13:36:28 +0000</pubDate>
      <link>https://dev.to/gabrielbabler/arraylist-vs-hashset-vs-hashmap-the-main-differences-389g</link>
      <guid>https://dev.to/gabrielbabler/arraylist-vs-hashset-vs-hashmap-the-main-differences-389g</guid>
      <description>&lt;p&gt;Hello, folks! Today I want to share with you the main differences between those three implementations of Collection from Java - ArrayList, HashSet, and HashMap.&lt;/p&gt;

&lt;p&gt;I chose those 3 because with them we can build a lot of solutions depending on the problem and, you can use them to help you through your logical challenges (HackerRank, LeetCode, etc).&lt;/p&gt;

&lt;p&gt;Note that, we have more implementations, so don't be stuck just with those three of this post. =) &lt;/p&gt;

&lt;p&gt;The objective of this post is to show you some differences between each implementation, and with that, you can choose the best one to solve your problem. &lt;/p&gt;

&lt;p&gt;First, what can we understand as a Collection?&lt;/p&gt;

&lt;p&gt;A collection is a set of data of the same type.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    "Gabriel",
    "John",
    "Alexa",
    "Bob"
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we can see a collection of names (or Strings). &lt;/p&gt;

&lt;p&gt;We can also have a collection of objects, 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;[
    {
        "name":"Gabriel",
        "age":26
    },
    {
        "name":"John"
        "age":30
    },
    {
        "name":"Alexa"
        "age":10
    },
    {
        "name":"Bob"
        "age":5
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ArrayList
&lt;/h2&gt;

&lt;p&gt;ArrayList is an implementation from the List interface.&lt;/p&gt;

&lt;p&gt;The ArrayList implementation is probably the first one you will have contact with when you start learning Java.&lt;/p&gt;

&lt;p&gt;So, when we are trying to create a list, like those examples of Collection above, in Java, we can use the ArrayList implementation to build it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;List&amp;lt;String&amp;gt; names = new ArrayList&amp;lt;&amp;gt;();&lt;/code&gt;&lt;br&gt;
&lt;code&gt;List&amp;lt;UserObject&amp;gt; users = new ArrayList&amp;lt;&amp;gt;();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What does using the ArrayList implementation give us?&lt;/p&gt;

&lt;p&gt;There are some methods implemented already in ArrayList, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;add(E e); &lt;br&gt;
(E is a generic type, I will create another post to talk more about it, basically, it means it can receive any Type as an argument - but of course, it has to respect the type of your List.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;get(int index);&lt;br&gt;
(index is the position where your data is present - remember that in a collection the index starts at 0)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;remove(int index);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;isEmpty();&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;size();&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html"&gt;more here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using ArrayList you can have a resizable list, removing or adding as much data as you want. &lt;/p&gt;
&lt;h2&gt;
  
  
  HashSet
&lt;/h2&gt;

&lt;p&gt;HashSet is an implementation from the Set interface.&lt;/p&gt;

&lt;p&gt;This implementation helps us to guarantee that our collection won't have repeated values, BUT it does not ensure sort.&lt;/p&gt;

&lt;p&gt;So, if we have a list called &lt;strong&gt;names&lt;/strong&gt;, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    "Gabriel",
    "John",
    "Gabriel",
    "Bob"
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to remove all the repeated values, we could create a new instance of HashSet and pass the list &lt;strong&gt;names&lt;/strong&gt; in the constructor, for example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Set&amp;lt;String&amp;gt; uniqueNames = new HashSet&amp;lt;&amp;gt;(names);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Just like the ArrayList, the HashSet implementation has some methods implemented as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;contains(Object o);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;add(E e);&lt;br&gt;
If you try to add an existing value it will just ignore it and not repeat it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;isEmpty();&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;remove(Object o);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;size();&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and &lt;a href="https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html"&gt;more here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HashMap
&lt;/h2&gt;

&lt;p&gt;HashMap is an implementation from the Map interface.&lt;/p&gt;

&lt;p&gt;HashMap works a little bit differently than HashSet and ArrayList, because it receives two parameters - the &lt;strong&gt;KEY&lt;/strong&gt; type and the &lt;strong&gt;VALUE&lt;/strong&gt; type.&lt;/p&gt;

&lt;p&gt;To instantiate a new HashMap we do this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Map&amp;lt;Integer, String&amp;gt; users = new HashMap&amp;lt;&amp;gt;();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;My first argument inside the &amp;lt;&amp;gt; is the type of my key - in this case an Integer. And the second one is the type of my value - in this case, a String. &lt;br&gt;
Note that we don't need to have the same types in both places. &lt;/p&gt;

&lt;p&gt;When we are working with HashMap, our KEY value is UNIQUE, so it won't be duplicated. But the value could be.&lt;/p&gt;

&lt;p&gt;Just like the previous ones, the HashMap implementation has some methods implemented as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;put(K key, V value);&lt;br&gt;
(Again, K and V here are generics and we are going to talk more about them in another post.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;get(Object key);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;getOrDefault(Object key, V defaultValue);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;isEmpty();&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;size();&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;containsValue(Object value);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;containsKey(Object key);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;putIfAbsent(K key, V value)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html"&gt;more here.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;I hope with this post now you can make use of those three collections to solve your daily problems.&lt;br&gt;
An excellent way to practice them is through HackerRank, LeetCode, or any other coding challenges platform.&lt;/p&gt;

&lt;p&gt;I hope I clarified the main differences between them and when you can choose one or another.&lt;/p&gt;

&lt;p&gt;Please, feel free to reach me if you have any suggestions, questions, or anything else.&lt;/p&gt;

&lt;p&gt;That's all folks! See you in the next post! =) &lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>RESTful - Understanding the most common HTTP verbs and Return Codes</title>
      <dc:creator>Gabriel Babler</dc:creator>
      <pubDate>Thu, 22 Sep 2022 02:44:04 +0000</pubDate>
      <link>https://dev.to/gabrielbabler/restful-understanding-the-most-common-http-verbs-and-return-codes-2g2o</link>
      <guid>https://dev.to/gabrielbabler/restful-understanding-the-most-common-http-verbs-and-return-codes-2g2o</guid>
      <description>&lt;p&gt;Hello folks! I want to share with you some knowledge about the most common HTTP verbs and Return Codes and an explanation about each one. I hope you enjoy it.&lt;/p&gt;

&lt;p&gt;First of all, when we are talking about &lt;strong&gt;RESTful&lt;/strong&gt;, we are talking about &lt;strong&gt;APIs&lt;/strong&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  But first, what is an API (Application Programming Interface)?
&lt;/h4&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%2Fb7q52o0i7y5dr44c5j2j.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%2Fb7q52o0i7y5dr44c5j2j.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.monosolutions.com/b/waiters-recipe-thieves-and-your-playlist-my-two-cents-on-apis" rel="noopener noreferrer"&gt;Image Source&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I love this image. It helps us to easily understand what is an API right away (at least it is what I hope. lol)&lt;/p&gt;

&lt;p&gt;So, basically in this image we can see a client, a waiter and, a chef. In this scenario our API is the &lt;strong&gt;waiter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Why? Because, we don't need to know &lt;em&gt;HOW&lt;/em&gt; the food is made, we just need to know how to &lt;em&gt;REQUEST&lt;/em&gt; the food.&lt;/p&gt;

&lt;p&gt;That's why the APIs are so important when we are trying to communicate between services, with a good documentation (e.g. &lt;a href="https://swagger.io/" rel="noopener noreferrer"&gt;swagger&lt;/a&gt;), we can see how to create the request and how the response will look like. &lt;/p&gt;

&lt;p&gt;Ok, after this brief explanation about what is an API, let's move on to the main topic of this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  RESTFul APIs
&lt;/h2&gt;

&lt;p&gt;Let's start talking about the most commons HTTP verbs used (&lt;strong&gt;based on my experience&lt;/strong&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET&lt;/li&gt;
&lt;li&gt;POST&lt;/li&gt;
&lt;li&gt;PUT&lt;/li&gt;
&lt;li&gt;DELETE&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And, in some scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PATCH&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We often see those verbs in applications that we call - &lt;em&gt;CRUD&lt;/em&gt; -&amp;gt; Create, Read, Update and Delete - applications.&lt;/p&gt;

&lt;p&gt;So, let's imagine a CRUD of Users. What does it mean? &lt;br&gt;
Our service will be responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save a new user in our database;&lt;/li&gt;
&lt;li&gt;Retrieve one/all the users from our database;&lt;/li&gt;
&lt;li&gt;Update an user information in the database;&lt;/li&gt;
&lt;li&gt;Delete an user information from the database;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And, in some scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partially update an user information in the database;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have the scenario ready, let's talk about each verb now.&lt;/p&gt;

&lt;h3&gt;
  
  
  GET
&lt;/h3&gt;

&lt;p&gt;We are going to use this verb every time we want to &lt;em&gt;RETRIEVE&lt;/em&gt; some information. In this scenario, we would use the GET to retrieve one or all the users from our database.&lt;/p&gt;

&lt;h3&gt;
  
  
  POST
&lt;/h3&gt;

&lt;p&gt;We are going to use this verb every time we want to &lt;em&gt;CREATE&lt;/em&gt; a new entry. In this scenario, we would use the POST to create a new user in our database.&lt;/p&gt;

&lt;h3&gt;
  
  
  PUT
&lt;/h3&gt;

&lt;p&gt;We are going to use this verb every time we want to &lt;em&gt;UPDATE&lt;/em&gt; an information. In this scenario, we would use the PUT to update a user information in our database.&lt;/p&gt;

&lt;h3&gt;
  
  
  DELETE
&lt;/h3&gt;

&lt;p&gt;We are going to use this verb every time we want to &lt;em&gt;DELETE&lt;/em&gt; an information. In this scenario, we would use the DELETE to delete a user information from our database.&lt;/p&gt;

&lt;h3&gt;
  
  
  PATCH
&lt;/h3&gt;

&lt;p&gt;We are going to use this verb every time we want to &lt;em&gt;PARTIALLY UPDATE&lt;/em&gt; a user information. In this scenario, we would use the PATCH to partially update a user information in our database.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let's just do a little comparative about POST vs PATCH, just to make the difference clear for you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  PUT vs PATCH
&lt;/h3&gt;

&lt;p&gt;Let's imagine that our User data in the database is composed by: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;name = Gabriel&lt;/li&gt;
&lt;li&gt;age = 25&lt;/li&gt;
&lt;li&gt;city = Campinas&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And now, let's see the differences between both requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PUT
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name":"Gabriel",
    "age": 26,
    "city": "Campinas"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;PATCH
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "age": 26
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What can we see here?&lt;/p&gt;

&lt;p&gt;Both request are doing the exactly same thing, updating the &lt;em&gt;age&lt;/em&gt; information from the user. &lt;/p&gt;

&lt;p&gt;But, the difference is, when we are using the PUT verb, we &lt;strong&gt;must&lt;/strong&gt; pass the whole object - even if nothing but age will be changed.&lt;/p&gt;

&lt;p&gt;Otherwise, if we have a PATCH endpoint configured, we can just pass the field we really want to change - more simple, isn't? &lt;/p&gt;

&lt;p&gt;Can I conclude here that our POST request and PUT request will be the same? Yes! You're completely right. &lt;/p&gt;

&lt;p&gt;There is some cases where the client tries to update a User, but the User does not exist in the database, so, instead of update the application creates a new User with that information.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ok, I hope you are understanding a little bit more about the verbs, now let's talk about the Return Codes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Return Codes
&lt;/h3&gt;

&lt;p&gt;There are lots of returns codes, really, you can check all of them &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;here&lt;/a&gt;. It goes from 100 until 599. (I meant it when I said a lot)&lt;/p&gt;

&lt;p&gt;Basically, what we can know about each range:&lt;/p&gt;

&lt;p&gt;100 - 199 -&amp;gt; Informational&lt;br&gt;
200 - 299 -&amp;gt; Success&lt;br&gt;
300 - 399 -&amp;gt; Redirect&lt;br&gt;
400 - 499 -&amp;gt; Client error&lt;br&gt;
500 - 599 -&amp;gt; Server error&lt;/p&gt;

&lt;p&gt;But the focus here is to show and explain the most common ones (&lt;strong&gt;based on my experience&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;So, keeping with our CRUD User scenario, let's go a little deeper and check our endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET /users&lt;/li&gt;
&lt;li&gt;GET /users/{userId}&lt;/li&gt;
&lt;li&gt;POST /users&lt;/li&gt;
&lt;li&gt;PUT /users/{userId}&lt;/li&gt;
&lt;li&gt;PATCH /users/{userId}&lt;/li&gt;
&lt;li&gt;DELETE /users/{userId}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Perfect! We talked about the verbs and, for your surprise, those verbs are linked with the return codes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Most common Return Codes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;200 (OK)&lt;/li&gt;
&lt;li&gt;201 (CREATED)&lt;/li&gt;
&lt;li&gt;204 (NO CONTENT)&lt;/li&gt;
&lt;li&gt;400 (BAD REQUEST)&lt;/li&gt;
&lt;li&gt;401 (UNAUTHORIZED)&lt;/li&gt;
&lt;li&gt;403 (FORBIDDEN)&lt;/li&gt;
&lt;li&gt;404 (NOT FOUND)&lt;/li&gt;
&lt;li&gt;405 (METHOD NOT ALLOWED)&lt;/li&gt;
&lt;li&gt;422 (UNPROCESSABLE ENTITY)&lt;/li&gt;
&lt;li&gt;500 (INTERNAL SERVER ERROR)&lt;/li&gt;
&lt;li&gt;502 (BAD GATEWAY)&lt;/li&gt;
&lt;li&gt;503 (SERVICE UNAVAILABLE)&lt;/li&gt;
&lt;li&gt;504 (GATEWAY TIMEOUT)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yes, that's are my most common return codes, let's see more about them.&lt;/p&gt;

&lt;h3&gt;
  
  
  200 (OK)
&lt;/h3&gt;

&lt;p&gt;It's pretty straight forward - your request has been executed successfully and you got your response body with all the information.&lt;br&gt;
We often use this return code for &lt;strong&gt;GET&lt;/strong&gt; requests.&lt;br&gt;
&lt;em&gt;There are scenarios where we return 200 for a POST request either - but that's for another post.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  201 (CREATED)
&lt;/h3&gt;

&lt;p&gt;When we are creating - POST - a new User into our database, the better return code for this scenario is this one. Without a body response.&lt;/p&gt;

&lt;h3&gt;
  
  
  204 (NO CONTENT)
&lt;/h3&gt;

&lt;p&gt;We often use this one when we are updating or deleting an information from our database. The client just need to know if his request works good. So, we don't need to retrieve a body response.&lt;/p&gt;

&lt;h3&gt;
  
  
  400 (BAD REQUEST)
&lt;/h3&gt;

&lt;p&gt;We use this return code when the client tries to make the request incorrectly, due a typo or whatever other reason. We return this error and a response body showing him what he did wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  401 (UNAUTHORIZED)
&lt;/h3&gt;

&lt;p&gt;When we have authentication in our application, we have to validate the credentials of the client before he could make the request. So, if the credentials are invalid, then we use this return code.&lt;/p&gt;

&lt;h3&gt;
  
  
  403 (FORBIDDEN)
&lt;/h3&gt;

&lt;p&gt;That's the next step after the validation of credentials, we will validate if those credentials have permission to access that particularly resource. &lt;/p&gt;

&lt;p&gt;So, based on our User scenario, a determined credential could retrieve all the users through the GET /users, but that credential could not DELETE or UPDATE a user, so it will receive a Forbidden if it tries.&lt;/p&gt;

&lt;h3&gt;
  
  
  404 (NOT FOUND)
&lt;/h3&gt;

&lt;p&gt;We are trying to retrieve just a user information through GET /users/{userId}, but the userId informed is not present in the database, then we return a NOT FOUND for the client.&lt;/p&gt;

&lt;h3&gt;
  
  
  405 (METHOD NOT ALLOWED)
&lt;/h3&gt;

&lt;p&gt;This one could be some causes, just a space in the end of the URL could cause it, or a wrong HTTP verb.&lt;/p&gt;

&lt;h3&gt;
  
  
  422 (UNPROCESSABLE ENTITY)
&lt;/h3&gt;

&lt;p&gt;I often use this one when something wrong goes with the business rule.&lt;/p&gt;

&lt;p&gt;For example, if we should only add users with 18+ years, and I try to add a younger user, my application should return a 422 with a response explaining the reason of that.&lt;/p&gt;

&lt;h3&gt;
  
  
  500 (INTERNAL SERVER ERROR)
&lt;/h3&gt;

&lt;p&gt;Pretty straight forward as well - an unexpected error happened in our code, then we use this one.&lt;/p&gt;

&lt;h3&gt;
  
  
  502 (BAD GATEWAY)
&lt;/h3&gt;

&lt;p&gt;Some architectures, in most cases, make usage of a Gateway - to grant more security and so - and this return code happens when the gateway receives an unexpected response, which it does not know how to process, then it returns this code.&lt;/p&gt;

&lt;h3&gt;
  
  
  503 (SERVICE UNAVAILABLE)
&lt;/h3&gt;

&lt;p&gt;When the application cannot process your request at that moment, it's not ready.&lt;/p&gt;

&lt;h3&gt;
  
  
  504 (GATEWAY TIMEOUT)
&lt;/h3&gt;

&lt;p&gt;As mentioned in the 502, we have a gateway between our request processing, but this time the gateway itself takes too long to process and throws a timeout.&lt;/p&gt;

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

&lt;p&gt;I hope it can help you all to understand a little bit more about the HTTP verbs and Return Codes used in the RESTful APIs. &lt;/p&gt;

&lt;p&gt;Also, a lot of that information already was asked for me in interviews. &lt;/p&gt;

&lt;p&gt;Tell me in the comments if you learned something new or even if you missed a HTTP verb or a Return Code that I didn't mention.&lt;/p&gt;

&lt;p&gt;So, I hope it could be useful for your careers. &lt;/p&gt;

&lt;p&gt;That's all folks! Hope you guys enjoyed. See you! &lt;/p&gt;

</description>
      <category>api</category>
      <category>restful</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
