<?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: Mateus Malaquias</title>
    <description>The latest articles on DEV Community by Mateus Malaquias (@malaquiasdev).</description>
    <link>https://dev.to/malaquiasdev</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%2F179488%2F7773492f-2026-4b22-97da-046736dee563.jpeg</url>
      <title>DEV Community: Mateus Malaquias</title>
      <link>https://dev.to/malaquiasdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/malaquiasdev"/>
    <language>en</language>
    <item>
      <title>Quarkus Testing: @QuarkusTest vs @QuarkusIntegrationTest</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Mon, 15 Dec 2025 12:56:27 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/quarkus-testing-quarkustest-vs-quarkusintegrationtest-4ihh</link>
      <guid>https://dev.to/malaquiasdev/quarkus-testing-quarkustest-vs-quarkusintegrationtest-4ihh</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Here is the cheat sheet:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;@QuarkusTest&lt;/th&gt;
&lt;th&gt;@QuarkusIntegrationTest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Process&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Same process (Shared JVM)&lt;/td&gt;
&lt;td&gt;External process (Separate JVM/Native)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;@Inject Beans&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Yes (Full Access)&lt;/td&gt;
&lt;td&gt;❌ No (Black Box)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mocking&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Yes (&lt;code&gt;@InjectMock&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;❌ No (Network only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Artifact&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Run against compiled classes&lt;/td&gt;
&lt;td&gt;Run against &lt;code&gt;.jar&lt;/code&gt;, Docker or Native Binary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Speed&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Faster (Dev Loop)&lt;/td&gt;
&lt;td&gt;Slower (Builds artifact first)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;@QuarkusTest&lt;/code&gt;&lt;/strong&gt; for 90% of your tests (logic, service layer, mocking).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;@QuarkusIntegrationTest&lt;/code&gt;&lt;/strong&gt; to verify the &lt;strong&gt;final artifact&lt;/strong&gt; (especially Native Image builds).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Confusion
&lt;/h2&gt;

&lt;p&gt;We have all been there. You write a beautiful test using &lt;code&gt;@QuarkusTest&lt;/code&gt;. You inject your repository, maybe mock an external service, and assert that your Service returns the correct DTO. Green lights everywhere.&lt;/p&gt;

&lt;p&gt;Then, you decide to be a "good citizen" and ensure your app works as a native binary. You copy-paste the test class, rename it to &lt;code&gt;MyResourceIT&lt;/code&gt;, and swap the annotation to &lt;code&gt;@QuarkusIntegrationTest&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boom. Exception.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This throws an error in @QuarkusIntegrationTest&lt;/span&gt;
&lt;span class="nd"&gt;@Inject&lt;/span&gt;
&lt;span class="nc"&gt;MyRepository&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suddenly, your &lt;code&gt;repository&lt;/code&gt; is null, or the test won't even start. You stare at the screen, wondering why Quarkus hates you.&lt;/p&gt;

&lt;p&gt;The problem isn't Quarkus. The problem is that despite looking similar, these two annotations work in completely different dimensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under the Hood: The Process Boundary
&lt;/h2&gt;

&lt;p&gt;The main difference—and the only one you really need to care about—is the &lt;strong&gt;Process Boundary&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. @QuarkusTest (White-Box)
&lt;/h3&gt;

&lt;p&gt;When you run this, Quarkus boots up &lt;strong&gt;inside the same process&lt;/strong&gt; as your test.&lt;/p&gt;

&lt;p&gt;Think of it like being inside the house. You are in the living room (the Test), and the application is in the kitchen.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can walk into the kitchen and change the ingredients (Mocking).&lt;/li&gt;
&lt;li&gt;You can grab food directly from the fridge (&lt;code&gt;@Inject&lt;/code&gt; Beans).&lt;/li&gt;
&lt;li&gt;Even when you use RestAssured to call an endpoint, the application is technically making a request to itself. It sounds weird, but it's legal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. @QuarkusIntegrationTest (Black-Box)
&lt;/h3&gt;

&lt;p&gt;This is where things change. This annotation tells Quarkus: &lt;em&gt;"Build the artifact (Jar or Native), spin it up in a separate process, and let me talk to it."&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now, you are &lt;strong&gt;locked out of the house&lt;/strong&gt;. You are standing on the sidewalk.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You cannot walk into the kitchen to mock things.&lt;/li&gt;
&lt;li&gt;You cannot reach into the fridge (&lt;code&gt;@Inject&lt;/code&gt; is impossible because the beans are in a different JVM process!).&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;only&lt;/strong&gt; shout through the window (HTTP Requests via RestAssured).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This runs against the &lt;strong&gt;packaged form&lt;/strong&gt; of the app. If you are testing a Native Image, the test runner starts the binary executable. You can't inject a Java Bean into a compiled binary running in a separate shell context.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use which?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prefer &lt;code&gt;@QuarkusTest&lt;/code&gt; when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You are doing TDD or the daily dev loop.&lt;/li&gt;
&lt;li&gt;You need to mock external dependencies (like a Payment Gateway or specific DB state).&lt;/li&gt;
&lt;li&gt;You need to verify internal logic that isn't exposed via the API.&lt;/li&gt;
&lt;li&gt;You want speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Prefer &lt;code&gt;@QuarkusIntegrationTest&lt;/code&gt; when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You need to verify the &lt;strong&gt;final build artifact&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native Mode:&lt;/strong&gt; This is crucial. Reflection behaves differently in Native images. Things that work in JVM might crash in Native. This test catches those issues.&lt;/li&gt;
&lt;li&gt;You want to test the application in a containerized environment (Docker/Podman).&lt;/li&gt;
&lt;li&gt;You want a true "Black Box" test where you strictly test public API contracts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;Don't try to force &lt;code&gt;@Inject&lt;/code&gt; into your Integration Tests. It won't work. If you find yourself needing to inspect the database state during an Integration Test, you have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Use a separate library to connect to the DB directly (bypassing the app's internal beans).&lt;/li&gt;
&lt;li&gt; Expose a specific "test-only" endpoint in your app to retrieve the data (but please, don't do this in production).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://quarkus.io/guides/getting-started-testing" rel="noopener noreferrer"&gt;Quarkus Guides: Testing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>quarkus</category>
      <category>java</category>
      <category>testing</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>[Quick Fix] Hibernate: object references an unsaved transient instance</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Mon, 08 Dec 2025 17:00:35 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/quick-fix-hibernate-object-references-an-unsaved-transient-instance-2ib8</link>
      <guid>https://dev.to/malaquiasdev/quick-fix-hibernate-object-references-an-unsaved-transient-instance-2ib8</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;You are likely trying to save an Entity that refers to another object that isn't saved in the database yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; just add &lt;code&gt;cascade = CascadeType.ALL&lt;/code&gt; to the relationship annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// In your Parent Entity (e.g. Order.java)&lt;/span&gt;
&lt;span class="nd"&gt;@OneToMany&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mappedBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"order"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cascade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CascadeType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ALL&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;--- Add this&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Scenario
&lt;/h2&gt;

&lt;p&gt;Here is the thing. You have an &lt;strong&gt;Order&lt;/strong&gt; and a list of &lt;strong&gt;OrderItems&lt;/strong&gt;. Classic relationship.&lt;/p&gt;

&lt;p&gt;You create the &lt;code&gt;Order&lt;/code&gt;, create an &lt;code&gt;OrderItem&lt;/code&gt;, add the item to the list, and try to save the &lt;strong&gt;Order&lt;/strong&gt; parent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setCustomer&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John Doe"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Creating a new child entity&lt;/span&gt;
&lt;span class="nc"&gt;OrderItem&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setProduct&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MacBook Pro"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setOrder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getItems&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Trying to save&lt;/span&gt;
&lt;span class="n"&gt;orderRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom. Exception.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Error
&lt;/h2&gt;

&lt;p&gt;The logs will scream this at you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why this happens
&lt;/h2&gt;

&lt;p&gt;Basically, Hibernate is confused.&lt;/p&gt;

&lt;p&gt;You have the &lt;code&gt;OrderItem&lt;/code&gt; in memory (Java heap), but it doesn't exist in the DB yet (no ID). When you call &lt;code&gt;.save(order)&lt;/code&gt;, Hibernate looks at the child object and freaks out because it doesn't know if it should save that child automatically or not.&lt;/p&gt;

&lt;p&gt;It stops the process to prevent data corruption. Ideally, it expects you to save the child manually first, but nobody wants to do that for every single item.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;We gotta tell JPA to just propagate the save operation.&lt;/p&gt;

&lt;p&gt;Go to your Parent entity and force the cascade.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before (The Error):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Entity&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="nd"&gt;@OneToMany&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mappedBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"order"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After (The Fix):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Entity&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="c1"&gt;// The Fix: Add CascadeType.ALL&lt;/span&gt;
    &lt;span class="nd"&gt;@OneToMany&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mappedBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"order"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cascade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CascadeType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ALL&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why this works
&lt;/h3&gt;

&lt;p&gt;Adding &lt;code&gt;CascadeType.ALL&lt;/code&gt; tells Hibernate: "If i save the Parent, save the Children too. If i delete the Parent, delete the Children."&lt;/p&gt;

&lt;p&gt;Simple as that. Now when you run &lt;code&gt;repository.save(order)&lt;/code&gt;, Hibernate handles the new &lt;code&gt;OrderItem&lt;/code&gt; insert automatically.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you are on legacy XML configs (I hope not), use &lt;code&gt;cascade="all"&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>java</category>
      <category>hibernate</category>
      <category>springboot</category>
      <category>quarkus</category>
    </item>
    <item>
      <title>How JWT, JWS, and JWE Secure Your Data?</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Fri, 14 Feb 2025 14:18:38 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/how-jwt-jws-and-jwe-secure-your-data-205a</link>
      <guid>https://dev.to/malaquiasdev/how-jwt-jws-and-jwe-secure-your-data-205a</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JWT (JSON Web Token)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;A compact format for securely transmitting information between parties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWS (JSON Web Signature)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;A signed JWT ensures the authenticity and data integrity, however, the data is public and not have encryption. If you need to keep the data private, use &lt;strong&gt;JWE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWE (JSON Web Encryption)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;It is an encrypted JWT, ensuring data confidentiality, however, does not ensure authenticity. Use when you need to keep the data private.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key differences
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;JWT&lt;/th&gt;
&lt;th&gt;JWS&lt;/th&gt;
&lt;th&gt;JWE&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Purpose&lt;/td&gt;
&lt;td&gt;Authentication and information exchange&lt;/td&gt;
&lt;td&gt;Signing data for integrity&lt;/td&gt;
&lt;td&gt;Encrypting data for confidentiality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payload&lt;/td&gt;
&lt;td&gt;Contains claims&lt;/td&gt;
&lt;td&gt;Signs an external payload&lt;/td&gt;
&lt;td&gt;Encrypted payload&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Structure&lt;/td&gt;
&lt;td&gt;Header, Payload, Signature&lt;/td&gt;
&lt;td&gt;Header, Signature&lt;/td&gt;
&lt;td&gt;Header, Encrypted Key, IV, Ciphertext, Auth Tag&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visibility&lt;/td&gt;
&lt;td&gt;Claims are visible&lt;/td&gt;
&lt;td&gt;Payload is visible&lt;/td&gt;
&lt;td&gt;Payload is encrypted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Are you covered?
&lt;/h2&gt;

&lt;p&gt;Secure tokens are a fundamental component of modern application, playing an important role in both authentication and authorization operations. These tokens serve as digital passports, allowing users to access sensitive systems and data. &lt;/p&gt;

&lt;p&gt;However, if they are mishandled because to incorrect storage, poor creation methods, or insufficient validation. They can lead to a slew of security vulnerabilities. &lt;/p&gt;

&lt;p&gt;Attackers may exploit vulnerabilities like as Cross-Site Scripting (XSS) or Cross-Site Request Forgery (CSRF), which can result in data breaches, identity theft, and unauthorised access to your systems. In other words, the integrity and secrecy of these tokens have a direct impact on your overall security posture.&lt;/p&gt;

&lt;p&gt;In this article, I will discuss the three important standards: JWT, JWS, and JWE. While they are connected, they serve distinct roles in safeguarding authentication and data transmission. &lt;/p&gt;

&lt;p&gt;Understanding their differences can assist you in determining the best approach for your application's security requirements.&lt;/p&gt;




&lt;h2&gt;
  
  
  JWT (JSON Web Token)
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;JWT&lt;/strong&gt; is essentially a way to safely transmit information between parties as a JSON object. It is compact, URL-safe, and designed to be used in web contexts. &lt;/p&gt;

&lt;p&gt;A typical JWT consists of three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt;: Specifies the token type (JWT) and signing algorithm (e.g., HMAC SHA256).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt;: Contains the claims (user data).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: Ensures the token's integrity by verifying the header and payload against the secret key.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Common use cases
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Authentication (e.g., OAuth 2.0, OpenID Connect)&lt;/li&gt;
&lt;li&gt;API authorization&lt;/li&gt;
&lt;li&gt;Information exchange between services&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why use JWT?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stateless:&lt;/strong&gt; The server does not need to store session information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portable:&lt;/strong&gt; Easily passed around via URL, POST parameters, or HTTP headers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Versatile:&lt;/strong&gt; Can be used for authentication, information exchange, and more.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  JWS (JSON Web Signature)
&lt;/h2&gt;

&lt;p&gt;JWS is a specification for signing arbitrary data to ensure its integrity and authenticity. It is always signed but does not inherently carry a payload; rather, it signs a payload provided separately.&lt;/p&gt;

&lt;p&gt;A JWS consists of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt; – Includes the signing algorithm (e.g., &lt;code&gt;RS256&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt; – The actual data, readable by anyone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt; – Created using a private key to validate authenticity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The JWS process involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Signing the Data:&lt;/strong&gt; The header and payload are signed using a specified algorithm (e.g., HMAC, RSA, or ECDSA).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verification:&lt;/strong&gt; The recipient can verify the signature with the corresponding secret or public key.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common use cases
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Token integrity (e.g., in OAuth 2.0 and OpenID Connect) to ensure they haven’t been altered.&lt;/li&gt;
&lt;li&gt;API authorization.&lt;/li&gt;
&lt;li&gt;Inter-Service messaging&lt;/li&gt;
&lt;li&gt;Document signing&lt;/li&gt;
&lt;li&gt;Secure data exchange when combine with encryption (JWE)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to use?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Integrity:&lt;/strong&gt; That the token’s contents haven’t been modified.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticity:&lt;/strong&gt; That the token comes from a trusted source.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  JWE
&lt;/h2&gt;

&lt;p&gt;Takes things one step further by not only signing the token but also encrypting it. This means that even if someone intercepts the token, they won’t be able to read its contents without the proper decryption key.&lt;/p&gt;

&lt;p&gt;A JWE consists of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt; – Defines the encryption algorithm (e.g., &lt;code&gt;RSA-OAEP&lt;/code&gt;, &lt;code&gt;A128GCM&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encrypted Key&lt;/strong&gt; – Encrypts the symmetric key used for content encryption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Initialization Vector&lt;/strong&gt; – Ensures randomness in encryption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ciphertext&lt;/strong&gt; – The encrypted payload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication Tag&lt;/strong&gt; – Ensures data integrity.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Common use cases
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Data confidentiality&lt;/li&gt;
&lt;li&gt;Secure API communication&lt;/li&gt;
&lt;li&gt;Nested token security use JWE alongside JWS for layered security (e.g., sign then encrypt a token)&lt;/li&gt;
&lt;li&gt;Inter-Service data protection&lt;/li&gt;
&lt;li&gt;Sensitive document protection&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to use?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Confidentiality is Required&lt;/strong&gt;: You want to keep the token’s payload hidden from unauthorized parties.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sensitive Data&lt;/strong&gt;: The token contains sensitive user data or permissions that should not be exposed.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Benefits of combining JWS and JWE
&lt;/h2&gt;

&lt;p&gt;Signing the data with JWS, can ensure that any modifications or tampering are immediately detectable, thereby verifying the authenticity and integrity of the information. &lt;/p&gt;

&lt;p&gt;Following this, encrypting the signed payload with JWE protects the contents from unauthorized access, ensuring that sensitive information remains confidential even if intercepted. &lt;/p&gt;

&lt;p&gt;This dual approach where the signature confirms the origin and integrity of the message and the encryption safeguards its privacy provides defense in depth, making it significantly more challenging for attackers to compromise the security of your data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Validate Tokens Rigorously:&lt;/strong&gt; Always check the token’s signature and expiration date before trusting its claims.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Strong Algorithms:&lt;/strong&gt; Avoid deprecated algorithms. Stick to modern, secure options like RS256 for signing and AES for encryption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep Secrets Safe:&lt;/strong&gt; Securely store keys and secrets used in signing or encryption. Compromised keys can lead to security breaches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement Token Revocation:&lt;/strong&gt; Consider strategies for revoking tokens if a breach is detected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Least Privilege Principle:&lt;/strong&gt; Only include the necessary information in your token and limit permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regularly Update Dependencies:&lt;/strong&gt; Keep libraries and dependencies up to date to mitigate vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/74257560/what-is-the-difference-between-jose-jwa-jwe-jwk-jws-and-jwt" rel="noopener noreferrer"&gt;Stack Overflow Discussion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.scottbrady.io/jose/json-web-encryption" rel="noopener noreferrer"&gt;Scott Brady's Post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codecurated.com/blog/introduction-to-jwt-jws-jwe-jwa-jwk/" rel="noopener noreferrer"&gt;Brilian Firdaus Post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.brunobrito.net.br/jose-jwt-jws-jwe-jwa-jwk-jwks/" rel="noopener noreferrer"&gt;Bruno Brito's Post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.loginradius.com/blog/engineering/guest-post/what-are-jwt-jws-jwe-jwk-jwa/" rel="noopener noreferrer"&gt;Yashesvinee's Post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.facilelogin.com/jwt-jws-and-jwe-for-not-so-dummies-b63310d201a3" rel="noopener noreferrer"&gt;Prabath Siriwardena's Post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.restack.io/docs/supabase-knowledge-difference-jwt-jws-supabase" rel="noopener noreferrer"&gt;Supabase JWT vs JWS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Photo by &lt;a href="https://unsplash.com/pt-br/@josenothose?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Jose Fontano&lt;/a&gt; in &lt;a href="https://unsplash.com/pt-br/fotografias/macro-tiro-de-cadeado-de-aco-inoxidavel-pZld9PiPDno?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>backend</category>
      <category>beginners</category>
      <category>security</category>
    </item>
    <item>
      <title>Tilde or Caret in package.json - Stop copying and start choosing</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Mon, 26 Feb 2024 18:14:23 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/tilde-or-caret-in-packagejson-stop-copying-and-start-choosing-4h3o</link>
      <guid>https://dev.to/malaquiasdev/tilde-or-caret-in-packagejson-stop-copying-and-start-choosing-4h3o</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Versions&lt;/th&gt;
&lt;th&gt;Dependency&lt;/th&gt;
&lt;th&gt;Impacts&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;tilde (~)&lt;/td&gt;
&lt;td&gt;1.6.X&lt;/td&gt;
&lt;td&gt;~1.6.7&lt;/td&gt;
&lt;td&gt;only bug fix can be upgrade&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;caret(^)&lt;/td&gt;
&lt;td&gt;1.X.X&lt;/td&gt;
&lt;td&gt;^1.6.7&lt;/td&gt;
&lt;td&gt;backwards compatible, deprecated and operational functionally, refactors, bug fix&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tilde (~):&lt;/strong&gt; Use it for libraries where stability is crucial. Example: express framework.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caret (^):&lt;/strong&gt; Use it for libraries where you want to benefit from new features and bug fixes. Example: Jest, Prettier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SEMVER
&lt;/h2&gt;

&lt;p&gt;SemVer is a convention, not a law. What happens when each number changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Major:&lt;/strong&gt; Something big has changed, and previous versions maybe will not work. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minor:&lt;/strong&gt; New features or improvements, things should still work mostly the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patch:&lt;/strong&gt; Solves small issues without changing the structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tilde (~)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Only allows &lt;strong&gt;patch updates&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Useful for getting the latest bug fixes and security patches while maintaining stability.&lt;/li&gt;
&lt;li&gt;Use it for libraries where stability is crucial. Example: express framework.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Caret (^)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Allow &lt;strong&gt;both minor and patch updates&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Useful for staying up-to-date with new features and improvements, however, we have a risk of potentially breaking changes.&lt;/li&gt;
&lt;li&gt;Use it for libraries where you want to benefit from new features and bug fixes. Example: Jest, Prettier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to update my dependencies?
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;This command will scan your code for outdated packages compare with the latest version in the &lt;a href="https://www.npmjs.com/"&gt;npm registry&lt;/a&gt; and no extra downloads needed because it is built into npm.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command will update the dependencies in package.json and package-lock.json using the "wanted" version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://semver.org/#semantic-versioning-200"&gt;Semantic Versioning 2.0.0&lt;/a&gt;&lt;br&gt;
&lt;a href="https://nodejs.org/en/blog/npm/peer-dependencies"&gt;Node.js - Peer Dependencies&lt;/a&gt;&lt;br&gt;
&lt;a href="https://nodejs.org/en/learn/getting-started/an-introduction-to-the-npm-package-manager"&gt;Node.js - An introduction to the npm package manager&lt;/a&gt;&lt;br&gt;
&lt;a href="https://unsplash.com/photos/q20F_rFKdCw"&gt;Thanks to masahiro miyagi @masamasa3 for making this photo available on Unsplash 🎁&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>yarn</category>
    </item>
    <item>
      <title>How to solve error parsing HTTP request header in Spring Boot</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Tue, 13 Feb 2024 11:44:02 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/how-to-solve-error-parsing-http-request-header-in-spring-boot-45pk</link>
      <guid>https://dev.to/malaquiasdev/how-to-solve-error-parsing-http-request-header-in-spring-boot-45pk</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Just add a line like below in your &lt;strong&gt;application.properties&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server.max-http-header-size=64kb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the limit header size to 64 kilobytes.&lt;/p&gt;




&lt;h2&gt;
  
  
  What are HTTP headers?
&lt;/h2&gt;

&lt;p&gt;According to Mozilla an &lt;strong&gt;HTTP header&lt;/strong&gt; is a field of an HTTP request or response that passes additional context and metadata about the request or response. For example, a request message can use headers to indicate its preferred media formats, while a response can use header to indicate the media format of the returned body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Spring Boot limit the header size?
&lt;/h2&gt;

&lt;p&gt;Well, large headers will consume more memory, they can slow down the request or worst crash our server. Limit them is a safety approach.&lt;/p&gt;

&lt;p&gt;Under the hood Spring Boot is not a server, indeed Spring can embedded 3 distinct servers, Tomcat, Jetty or Undertow. However, the configuration for them will be the same.&lt;/p&gt;

&lt;p&gt;The default header size are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tomcat = 8kb&lt;/li&gt;
&lt;li&gt;Jetty = 8kb&lt;/li&gt;
&lt;li&gt;Undertow = 1mb&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To change the max size, follow the &lt;strong&gt;TL;DR&lt;/strong&gt; example.&lt;/p&gt;

&lt;p&gt;Be careful when increasing the size limit always analise your situation and try to understand why the header is too large (usually are auth token).&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header"&gt;MDN Web Doc: HTTP header&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.spring.io/spring-boot/docs/1.5.22.RELEASE/reference/html/common-application-properties.html"&gt;Spring Boot Doc: Common application properties&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>kotlin</category>
      <category>spring</category>
      <category>springboot</category>
    </item>
    <item>
      <title>When I prefer use when then if-else in Kotlin</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Mon, 05 Feb 2024 15:41:05 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/when-i-prefer-use-when-then-if-else-in-kotlin-24ok</link>
      <guid>https://dev.to/malaquiasdev/when-i-prefer-use-when-then-if-else-in-kotlin-24ok</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;if-else&lt;/code&gt; for simple cases with only one conditions or to use &lt;a href="https://dev.to/malaquiasdev/why-i-like-to-use-early-returns-pattern-52b2"&gt;early returns pattern&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;when&lt;/code&gt; for more complex cases with multiple conditions and to have a cleaner code.&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;Ever feel lost in a maze of &lt;code&gt;if-else&lt;/code&gt; statements, desperately trying to handle every input nuance? Fear not, fellow dev! Kotlin's &lt;code&gt;when&lt;/code&gt; statement offers a sleek and powerful escape route.&lt;br&gt;
Forget the Java &lt;code&gt;switch&lt;/code&gt; cases or the endless &lt;code&gt;else if&lt;/code&gt; that makes your code's readability horrible. &lt;code&gt;when&lt;/code&gt; can simplify your logic, writing multiple conditions into a single and clear block.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why &lt;code&gt;when&lt;/code&gt; is better in my option?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clean Code: allows you to write more concise and readable code, especially when you need to check multiple conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type Safe: runtime mistakes can be avoided by checking the expression against each case value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extensibility: can be easily extended to handle new cases.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun renderRequests(userId: String) = renderComponent {
  val user = getUser(userId)
    when (user.role) {
      is ROLE.CHILD -&amp;gt; return
      is ROLE.UNCLE -&amp;gt; defaultRequestError()
      is ROLE.PARENT -&amp;gt; {
        buildRenderComponent(user)
      }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now compare with if-else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun renderRequests(userId: String) = renderComponent {
  val user = getUser(userId)
   if (user.role == ROLE.CHILD) {
    return
   } else if (user.role == ROLE.UNCLE) {
    defaultRequestError()
   } else if (user.role == ROLE.PARENT) {
    buildRenderComponent(user)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When &lt;code&gt;if-else&lt;/code&gt; is a better option?
&lt;/h2&gt;

&lt;p&gt;When I want to use &lt;a href="https://dev.to/malaquiasdev/why-i-like-to-use-early-returns-pattern-52b2"&gt;early returns pattern&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Writing functions or methods, early return means that the expected positive result is returned at the end of the function, and when conditions are not met, the rest of the code ends the execution by returning or throwing an exception.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun sayMyName(name: String): String {
 if (!name || name.length &amp;lt; 0) {
    return;
  }
  return `Hello, ${name}`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kotlinlang.org/docs/control-flow.html"&gt;Kotlin documentation on control flow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.baeldung.com/kotlin/when"&gt;Baeldung tutorial on when&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://typealias.com/start/kotlin-conditionals/"&gt;Kotlin: An Illustrated Guide • Chapter 3 - Kotlin Conditionals: When and If&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kotlin</category>
      <category>programming</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>Why I like to use Early Returns Pattern?</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Fri, 07 Oct 2022 13:22:34 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/why-i-like-to-use-early-returns-pattern-52b2</link>
      <guid>https://dev.to/malaquiasdev/why-i-like-to-use-early-returns-pattern-52b2</guid>
      <description>&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%2F7kiy274h1kg8i7etqcmf.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%2F7kiy274h1kg8i7etqcmf.png" alt="Thanks to Sarah Kilian @rojekilian for making this photo available freely on Unsplash 🎁"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://unsplash.com/photos/52jRtc2S_VE" rel="noopener noreferrer"&gt;Thanks to Sarah Kilian @rojekilian for making this photo available freely on Unsplash 🎁&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to start this article by saying that I didn't like to use &lt;strong&gt;early returns&lt;/strong&gt; in the beginning, however, with time and paring with members of my team, I understood how this simple pattern is strong.&lt;/p&gt;

&lt;p&gt;I learned bad habits in my first years as a programmer and, it's OK to develop new ones. Let's see an example from my daily life.&lt;/p&gt;

&lt;h2&gt;
  
  
  How fast a simple code can mess up everything?
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDeliveryType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Client&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;prod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&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="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getClientAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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;address&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="nx"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;calculateFee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&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;fee&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;delivery&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;online&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above was a simple idea to get the delivery type, this is a perfect example to help us understand the power of applying early returns without messing up the code.&lt;/p&gt;

&lt;p&gt;What can we observe in the code?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code isn't linear, if we put more validations will be hard to understand all the conditions.&lt;/li&gt;
&lt;li&gt;We need to navigate through the &lt;em&gt;ifs&lt;/em&gt; to see the positive response.&lt;/li&gt;
&lt;li&gt;It's confusing to read because of the struct created by &lt;em&gt;if-else&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Besides, we get two anti-patterns: &lt;a href="http://wiki.c2.com/?ElseConsideredSmelly" rel="noopener noreferrer"&gt;Else is considered smelly&lt;/a&gt; and &lt;a href="http://wiki.c2.com/?ArrowAntiPattern" rel="noopener noreferrer"&gt;Arrow anti-pattern&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is an early return?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An approach to keep readability in functions and methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;😂&lt;/strong&gt; Yeah, the answer is pretty simple.&lt;/p&gt;

&lt;p&gt;When writing functions or methods, early return means that the expected positive result is returned at the end of the function, and when conditions are not met, the rest of the code ends the execution by returning or throwing an exception.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayMyName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&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;name&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&lt;code&gt;Hello, &amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;${&amp;lt;/span&amp;gt;&amp;lt;span class="nx"&amp;gt;name&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;&amp;lt;span class="s2"&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Refactoring the code to use the Early Returns Pattern&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Like I said too many &lt;em&gt;if-else&lt;/em&gt; can make it hard to follow the code. I like this approach because the indentation helps me to focus on understanding ”what this code does?” and not on “what's going on here?”&lt;/p&gt;

&lt;p&gt;Let's refactor the example code.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDeliveryType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&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;prod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getClientAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p&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;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;calculateFee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;delivery&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  What can we observe now?&lt;br&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The code has one indentation level.&lt;/li&gt;
&lt;li&gt;It’s easy and fast to read the code.&lt;/li&gt;
&lt;li&gt;The positive result stays at the end of the function.&lt;/li&gt;
&lt;li&gt;We can find our logic/business errors first, and in the log term will help us to avoid mistakes and bugs.&lt;/li&gt;
&lt;li&gt;Now we have a fail-fast design pattern 🙂.&lt;/li&gt;
&lt;li&gt;The function ends immediately on errors.&lt;/li&gt;
&lt;li&gt;With this mindset, we implement a list of design patterns: &lt;a href="https://www.martinfowler.com/ieeeSoftware/failFast.pdf" rel="noopener noreferrer"&gt;Fail Fast&lt;/a&gt;, &lt;a href="https://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html" rel="noopener noreferrer"&gt;Guard Clause&lt;/a&gt;, &lt;a href="https://wiki.c2.com/?BouncerPattern" rel="noopener noreferrer"&gt;Bouncer Pattern&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;I recommend you to adopt as a style guideline, however, this is a subjective thing, so it's your decision whether to use it or not.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>node</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Lombok: Fixing SonarQube coverage problem</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Wed, 13 Oct 2021 21:16:17 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/lombok-fixing-sonarqube-coverage-problem-26bg</link>
      <guid>https://dev.to/malaquiasdev/lombok-fixing-sonarqube-coverage-problem-26bg</guid>
      <description>&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@scottrodgerson?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Scott Rodgerson&lt;/a&gt; on &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/malaquiasdev/lombok-corrigindo-problema-de-cobertura-de-codigo-no-sonarqube-570h"&gt;Here is a Portuguese version.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my ongoing project, I have a CI/CD flow and one step is responsible to collect the code coverage and validate if I have the minimal value to proceed to another step.&lt;/p&gt;

&lt;p&gt;However, even having 84% of code coverage, the SonarQube always returned 30% of the result in the step, because of that the deployment step was never executed. &lt;/p&gt;

&lt;p&gt;I spent some time understanding that the problem was in the Lombok annotations, the SonarQube was computing the generated code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution:
&lt;/h2&gt;

&lt;p&gt;It's simple to resolve this issue. I created a file named &lt;code&gt;lombok.config&lt;/code&gt; inside the folder java &lt;em&gt;(/../src/main/java/lombok.config)&lt;/em&gt; with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What are these settings for?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;config.stopBubbling&lt;/code&gt; informs the Lombok that the folder where the file is the root and the Lombok don't need to search for more parent folders.&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;lombok.addLombokGeneratedAnnotation&lt;/code&gt;  put in every generated code by Lombok annotation, another one named &lt;code&gt;@lombok.Generated&lt;/code&gt;. This annotation informs Jacoco to not collect coverage from those codes.&lt;/p&gt;

&lt;p&gt;Done, problem solved!&lt;/p&gt;

&lt;h2&gt;
  
  
  Finishing...
&lt;/h2&gt;

&lt;p&gt;If you liked this post, please be sure to like and share 😄&lt;/p&gt;

&lt;p&gt;If you want to know what I'm doing out there or ask any questions, feel free to look for me on social networks like &lt;a href="https://twitter.com/malaquiasdev"&gt;@malaquiasdev&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To read more of my posts, go to &lt;a href="http://malaquias.dev/tags/english"&gt;MalaquiasDEV | Life, the code and everything else.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>devops</category>
      <category>testing</category>
    </item>
    <item>
      <title>Lombok: Corrigindo problema de cobertura de código no SonarQube</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Wed, 06 Oct 2021 12:20:43 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/lombok-corrigindo-problema-de-cobertura-de-codigo-no-sonarqube-570h</link>
      <guid>https://dev.to/malaquiasdev/lombok-corrigindo-problema-de-cobertura-de-codigo-no-sonarqube-570h</guid>
      <description>&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@scottrodgerson?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Scott Rodgerson&lt;/a&gt; on &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;No meu projeto atual temos um fluxo de CI/CD automatizado e uma das responsabilidades desse fluxo é detectar se estamos cumprindo a taxa mínima de cobertura de código estabelecida pelo time. &lt;/p&gt;

&lt;p&gt;Entretanto, mesmo possuindo uma cobertura de código com 84% o SonarQube estava sempre informando 30% como resultado, por causa dessa taxa tão baixa o processo de CI/CD parava e o deploy não acontecia.&lt;/p&gt;

&lt;p&gt;Demorou um tempo para eu entender que o SonarQube também estava computando a parte do código criada pelas anotações do Lombok.&lt;/p&gt;

&lt;h2&gt;
  
  
  A solução para o problema:
&lt;/h2&gt;

&lt;p&gt;A solução é muito simples. Precisei criar um arquivo chamado &lt;code&gt;lombok.config&lt;/code&gt; na pasta java &lt;em&gt;(/../src/main/java/lombok.config)&lt;/em&gt; com os valores abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Para que serve essas configurações?
&lt;/h2&gt;

&lt;p&gt;O &lt;code&gt;config.stopBubbling&lt;/code&gt; está informando que a pasta onde o arquivo se encontra é a raiz do projeto e o Lombok não deve procurar arquivos de configurações em outras pastas.&lt;/p&gt;

&lt;p&gt;Enquanto &lt;code&gt;lombok.addLombokGeneratedAnnotation&lt;/code&gt; está configurando o Lombok para adicionar uma anotação &lt;code&gt;@lombok.Generated&lt;/code&gt; em todos os métodos criados por alguma anotação.&lt;/p&gt;

&lt;p&gt;E é exatamente isso que queremos porque o plugin Jacoco responsável por coletar a cobertura de código do projeto e informa ao SonarQube vai passar a ignorar todos os métodos que tiverem essa anotação.&lt;/p&gt;

&lt;p&gt;Pronto, problema resolvido. Depois que você aplicar essas configurações a cobertura de código do seu projeto deve voltar ao normal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finalizando...
&lt;/h2&gt;

&lt;p&gt;Se você gostou desse post, por favor não deixe de dar um like e compartilhar 😄&lt;/p&gt;

&lt;p&gt;Se quiser saber o que ando fazendo por aí ou tirar alguma dúvida fique a vontade para me procurar nas redes sociais como @ &lt;a href="https://twitter.com/malaquiasdev"&gt;malaquiasdev&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Para ler mais post meus acesse &lt;a href="http://malaquias.dev/"&gt;MalaquiasDEV | A Vida, o código e tudo mais&lt;/a&gt; .&lt;/p&gt;

</description>
      <category>java</category>
      <category>devops</category>
      <category>testing</category>
    </item>
    <item>
      <title>Weekly Edição 1</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Sun, 28 Feb 2021 12:06:13 +0000</pubDate>
      <link>https://dev.to/malaquiasdev/weekly-edicao-1-ela</link>
      <guid>https://dev.to/malaquiasdev/weekly-edicao-1-ela</guid>
      <description>&lt;p&gt;Weekly é uma sessão do blog onde guardo todos os links dos conteúdos que li, ouvi ou assistir durante uma semana. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;📚&lt;/strong&gt; Textos:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Abba:&lt;/strong&gt; &lt;a href="https://abba.dev/blog/dynamodb-partiql-javascript"&gt;Using PartiQL to query AWS DynamoDb in Javascript&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ali Abdaal:&lt;/strong&gt; &lt;a href="https://aliabdaal.com/studying/"&gt;The Ultimate Guide to Studying&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flavio Copes:&lt;/strong&gt; &lt;a href="https://flaviocopes.com/node-write-csv/"&gt;How to write a CSV file with Node.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ali Abdaal:&lt;/strong&gt; &lt;a href="https://aliabdaal.com/useful-productivity-studying-apps/"&gt;Useful Apps To Improve Productivity and Study Effectively&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simon Holdorf:&lt;/strong&gt; &lt;a&gt;Why You Need Soft Skills as a Software Developer – And How to Improve Them&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Natalie Pina:&lt;/strong&gt; &lt;a href="https://www.freecodecamp.org/news/how-empathy-makes-you-a-better-software-engineer/"&gt;How Empathy Can Make You a Better Software Engineer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tiago de Freitas Lima:&lt;/strong&gt; &lt;a href="https://elo7.dev/microservicos-rest/"&gt;Microserviços e REST (sério?)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Marvin Mouroum:&lt;/strong&gt; &lt;a href="https://medium.com/flawless-app-stories/ios-push-notifications-with-aws-4bde95dfe7f4"&gt;iOS Dynamic Push Notifications with AWS Pinpoint&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;🎙&lt;/strong&gt; Podcasts:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Charles Duhigg:&lt;/strong&gt; &lt;a href="https://12min.com/br/o-poder-do-habito-resumo"&gt;O Poder do Hábito&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tallis Gomes:&lt;/strong&gt; &lt;a href="https://12min.com/br/nada-easy-resumo#"&gt;Nada Easy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sun Tzu:&lt;/strong&gt; &lt;a href="https://12min.com/br/a-arte-da-guerra-resumo"&gt;A Arte da Guerra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hipsters:&lt;/strong&gt; &lt;a href="https://hipsters.tech/o-ecossistema-frontend-da-gupy-hipsters-on-the-road-52/"&gt;O Ecossistema Frontend da Gupy – Hipsters On The Road #52&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hipsters:&lt;/strong&gt; &lt;a href="https://hipsters.tech/estado-atual-do-devops-hipsters-ponto-tech-240/"&gt;Estado atual do DevOps – Hipsters Ponto Tech #240&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hipsters:&lt;/strong&gt; &lt;a href="https://hipsters.tech/trello-jira-e-ferramentas-de-produtividade-hipsters-ponto-tech-239/"&gt;Trello, Jira e Ferramentas de Produtividade – Hipsters Ponto Tech #239&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nath Finanças:&lt;/strong&gt; &lt;a href="https://12min.com/br/orcamento-sem-falhas"&gt;Orçamento Sem Falhas&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🗣 Tweets:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/rponte"&gt;@rponte&lt;/a&gt;: &lt;a href="https://twitter.com/rponte/status/1363994140866977797"&gt;"&lt;/a&gt;&lt;/strong&gt; &lt;a href="https://twitter.com/rponte/status/1363994140866977797"&gt;alguém tem algum artigo sobre boas práticas em design de APIs gRPC (ou mesmo RPC)?"&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🖥️ Videos:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Beto Muniz:&lt;/strong&gt; &lt;a href="https://www.youtube.com/watch?v=hBCzE96apao"&gt;Desenvolvimento Web Além do HTML, CSS e JavaScript - YouTube&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rocketseat:&lt;/strong&gt; &lt;a href="https://www.youtube.com/watch?v=W-SOgt7O1hc"&gt;Node.js: carreira, mercado e dicas na prática | #PR  27&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Publicando pacotes privados do NPM no Nexus repository</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Tue, 23 Jun 2020 17:58:43 +0000</pubDate>
      <link>https://dev.to/collabcode/publicando-pacotes-privados-do-npm-no-nexus-repository-64l</link>
      <guid>https://dev.to/collabcode/publicando-pacotes-privados-do-npm-no-nexus-repository-64l</guid>
      <description>&lt;p&gt;Atualmente trabalho com JavaScript e Node.js em uma grande operadora daqui do Brasil e muitas de nossas soluções não podem estar públicas na internet por questões de segurança.&lt;/p&gt;

&lt;p&gt;No projeto que trabalho temos o costume de compartilhar módulos JavaScript entre microserviços para aumentar nossa produtividade.&lt;/p&gt;

&lt;p&gt;Isso no levou a desenvolver muitas libs internas, até então estávamos utilizando um gitlab interno como repositório de pacote para essas libs, mas o processo de governança e publicação não ficou muito bom.&lt;/p&gt;

&lt;p&gt;Por isso migramos para o Nexus Repository Manager (também conhecido como Nexus), que é um gerenciador de repositório de código aberto fornecido pelo Sonatype.&lt;/p&gt;

&lt;p&gt;A nossa intenção é continuar usando o NPM e tudo aquilo que a comunidade JavaScript pode nos oferecer de open-source. Combinando com nossas libs privadas do Nexus, além de conseguir utilizar de maneira decente um processo de controle de pacotes.&lt;/p&gt;

&lt;p&gt;Neste artigo vamos ver um resumo de porque escolhemos o Nexus como repositório privado, como configura-ló para funcionar com o NPM e como conseguir consumir os pacotes guardados no Nexus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Por que não estamos usando os produtos do NPM?
&lt;/h2&gt;

&lt;p&gt;Bem, aqui a gente entra um pouco no processo de contratação de serviço da empresa, geralmente não se contrata ou compra serviços que vão atender a somente um time, como temos muitos projetos e muitos times trabalhando a empresa tenta contratar o serviço para o máximo de times possíveis.&lt;/p&gt;

&lt;p&gt;No momento que estou escrevendo esse artigo o NPM a nível enterprise que possuí toda a estrutura de serviços que uma grande corporação precisa está custando ao &lt;strong&gt;mês&lt;/strong&gt; 10 mil dólares.&lt;/p&gt;

&lt;p&gt;Com 10 mil dólares nosso time de DevOps é capaz de subir toda infraestrutura necessária, configurar backups regulares, camadas de segurança e ainda vai sobrar bastante dinheiro porque o Nexus pode atender diversas plataformas de programação.&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%2Fmalaquias.dev%2Fstatic%2F8500637b87f3392c96d166bfe967a419%2F0a3bd%2Fnexus.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%2Fmalaquias.dev%2Fstatic%2F8500637b87f3392c96d166bfe967a419%2F0a3bd%2Fnexus.png" alt="Nexus diagrama"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Se você só utiliza JavaScript em seus projetos e pode pagar pelos produtos oferecidos pelo NPM ou não possuiu um time que possa manter uma infraestrutura decente para você, recomendo optar pelo NPM.&lt;/p&gt;

&lt;h2&gt;
  
  
  O mínimo que você precisa saber para prosseguir
&lt;/h2&gt;

&lt;p&gt;O Nexus vai expor para você um repositório “publico” chamado &lt;code&gt;group&lt;/code&gt; que internamente é combinação do nosso repositório privado, ou seja, &lt;code&gt;hosted&lt;/code&gt; e um &lt;code&gt;proxy&lt;/code&gt; para o registro público do NPM.&lt;/p&gt;

&lt;p&gt;O proxy é extremamente importante se seu projeto precisa utilizar libs open source que estão hospedadas no NPM ou em qualquer outro repositório que não seja o teu Nexus.&lt;/p&gt;

&lt;p&gt;Por padrão sempre que a gente consumir um pacote publico o Nexus vai criar um cache para que a gente não precise acessar o NPM a todo momento por exemplo.&lt;/p&gt;

&lt;p&gt;No final de nossa configuração teremos a seguinte somatória &lt;code&gt;group = hosted + proxy&lt;/code&gt; e nosso fluxo de uso será sempre baixar os pacotes do &lt;code&gt;group&lt;/code&gt; e fazer uploads para o &lt;code&gt;hosted&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%2Fmalaquias.dev%2Fstatic%2Fac29c7b8bff154b3ab7ea41ab014fdc8%2F3fc71%2Fnexus-repositories.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%2Fmalaquias.dev%2Fstatic%2Fac29c7b8bff154b3ab7ea41ab014fdc8%2F3fc71%2Fnexus-repositories.png" alt="Nexus Repositorios"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No fim, vamos arregaçar um pouco as mangas e entender.&lt;/p&gt;

&lt;h2&gt;
  
  
  Criando um repositório Host
&lt;/h2&gt;

&lt;p&gt;Repositórios hospedados são os repositórios particulares que criamos para armazenar nossos pacotes particulares. O que torna esses repositórios privados é a incapacidade de ler o conteúdo desses repositórios sem um authToken. Veremos isso em um exemplo no final do artigo.&lt;/p&gt;

&lt;p&gt;Para criar um repositório do tipo &lt;code&gt;hosted&lt;/code&gt; vá em &lt;code&gt;Settings =&amp;gt; Repository =&amp;gt; Repositories =&amp;gt; Create Repository&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Depois de clicar em &lt;strong&gt;Create Repository&lt;/strong&gt; o Nexus vai nos exibir uma quantidade enorme de plataformas que gerenciam dependências. Se for sua primeira vez usando Nexus, aproveite a oportunidade para da uma explorada no que a plataforma pode te oferecer.&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%2Fmalaquias.dev%2Fstatic%2Ffae6124cc16421c195fa8f02bb06322f%2F3fc71%2Fnexus-npm-all.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%2Fmalaquias.dev%2Fstatic%2Ffae6124cc16421c195fa8f02bb06322f%2F3fc71%2Fnexus-npm-all.png" alt="Nexus Repositorios"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dessa lista vamos focar no &lt;strong&gt;npm&lt;/strong&gt;, o primeiro repositório que vamos será &lt;code&gt;npm(hosted)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Na tela de criação o Nexus vai nos solicitar um nome &lt;strong&gt;único&lt;/strong&gt; e em storage vamos guardar os nossos artefatos.&lt;/p&gt;

&lt;p&gt;E é isso, basta clicar no botão &lt;strong&gt;Create Repository&lt;/strong&gt; para finalizar.&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%2Fmalaquias.dev%2Fstatic%2F5e9805b65f6b3cdf0dd3f7b7e55e65db%2F3fc71%2Fnexus-npm-private.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%2Fmalaquias.dev%2Fstatic%2F5e9805b65f6b3cdf0dd3f7b7e55e65db%2F3fc71%2Fnexus-npm-private.png" alt="Nexus NPM Private"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Criando um proxy e grupo do NPM
&lt;/h2&gt;

&lt;p&gt;Volte novamente para &lt;code&gt;Repository =&amp;gt; Repositories =&amp;gt; Create Repository&lt;/code&gt;, para criamos um novo repositório do tipo &lt;code&gt;npm(proxy)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Na tela de configuração nos vamos especificar que queremos nos comunicar com o NPM no campo &lt;strong&gt;Proxy Location&lt;/strong&gt; adicionando a URL &lt;code&gt;https://registry.npmjs.org&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%2Fmalaquias.dev%2Fstatic%2Fc12f87dca1268a148a2f79a16dddb5a2%2F3fc71%2Fnexus-npm-proxy.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%2Fmalaquias.dev%2Fstatic%2Fc12f87dca1268a148a2f79a16dddb5a2%2F3fc71%2Fnexus-npm-proxy.png" alt="Nexus NPM Proxy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Com os repositórios &lt;code&gt;npm(hosted) e npm(proxy)&lt;/code&gt; criados, podemos finalmente criar o &lt;code&gt;npm(group)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;O fluxo de configurações é igual aos anteriores, coloque um nome e informe o mesmo store utilizado em &lt;code&gt;npm(hosted) e npm(proxy)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Além disso precisamos selecionar os usuários ou grupos que podem acessar o repositório &lt;code&gt;npm(group)&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%2Fmalaquias.dev%2Fstatic%2F2880df6b01d449b7a6b207ed5ac2852d%2F3fc71%2Fnexus-npm-group.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%2Fmalaquias.dev%2Fstatic%2F2880df6b01d449b7a6b207ed5ac2852d%2F3fc71%2Fnexus-npm-group.png" alt="Nexus NPM Group"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Enviando pacotes para o Nexus
&lt;/h2&gt;

&lt;p&gt;Agora que estamos prontos com os repositórios criados, podemos configurar nossos projetos.&lt;/p&gt;

&lt;p&gt;Para publicar um artefato no Nexus, precisamos alterar o arquivo &lt;strong&gt;package.json&lt;/strong&gt; adicionando um objeto chamado &lt;strong&gt;publishConfig&lt;/strong&gt; que vai guardar a &lt;strong&gt;URL&lt;/strong&gt; do nosso repositório &lt;strong&gt;privado&lt;/strong&gt;.&lt;/p&gt;

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

{
  "name": "@ms-ott/tools",
  "version": "2.0.4",
  "description": "Common and helpers tools to create microservices APIs",
  "main": "src/index.js",
  "publishConfig": {
    "registry": "https://meu.dominio.com/repository/npm-private/"
  },
  "scripts": {
    "lint": "eslint \"{src,apps,libs,test}/**/*.js\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage"
  },
  "devDependencies": {
    "eslint": "^5.16.0",
   "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-prettier": "^3.0.1",
    "jest": "^24.7.1",
    "prettier": "^1.16.4"
  },
  "dependencies": {
    "aws-sdk": "^2.263.1",
    "dotenv": "^5.0.1",
    "dynamoose": "^1.7.3",
    "joi": "^13.4.0",
    "jsonwebtoken": "^8.5.1",
    "node-cache": "^4.2.0",
    "restify-cors-middleware": "^1.1.1",
    "restify-errors": "^8.0.1",
    "uuid": "^3.3.3",
    "request": "^2.83.0",
    "request-ip": "^2.1.3",
    "winston": "^3.2.1"
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Com o &lt;strong&gt;package.json&lt;/strong&gt; configurado, agora precisamos fazer um login no npm cli apontando o &lt;strong&gt;registry&lt;/strong&gt; para o nosso domínio:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm login —registry=https://meu.dominio.com/repository/npm-private/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Digite seu usuário e senha do nexus e pronto. 🧞&lt;/p&gt;

&lt;p&gt;Agora basta executar o comando: &lt;code&gt;npm publish&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%2Fmalaquias.dev%2Fstatic%2F1df35565a23c8d3b2174f19faa7bc013%2Fe7746%2Fnpm-publish-command.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%2Fmalaquias.dev%2Fstatic%2F1df35565a23c8d3b2174f19faa7bc013%2Fe7746%2Fnpm-publish-command.png" alt="NPM Publish"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Se tudo deu certo você vai conseguir verificar sua lib hospedado acessando o repositório privado.&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%2Fmalaquias.dev%2Fstatic%2F8088d13e87d13adf8e992b38b05ad219%2F3fc71%2Fverificando-lib-repo-nexus.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%2Fmalaquias.dev%2Fstatic%2F8088d13e87d13adf8e992b38b05ad219%2F3fc71%2Fverificando-lib-repo-nexus.png" alt="Verificando lib no Nexus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Baixando seus pacotes do Nexus
&lt;/h2&gt;

&lt;p&gt;Agora que publicamos nossa lib no Nexus, vamos consumi-la em outros projetos.&lt;/p&gt;

&lt;p&gt;Precisamos adicionar um arquivo &lt;strong&gt;.npmrc&lt;/strong&gt; no projeto, para evitar que toda pessoa desenvolvedora do time precise fazer um npm login apontando o registry para o Nexus.&lt;/p&gt;

&lt;p&gt;O arquivo &lt;strong&gt;.npmrc&lt;/strong&gt; vai guardar tanto a URL do Nexus como um authToken com permissão de acesso.&lt;/p&gt;

&lt;h4&gt;
  
  
  Como boa prática, recomendo que você possua configurado em seu Nexus um usuário com permissão de somente leitura que possa ser usado para um fluxo de CI/CD e que você possa deixar o arquivo .npmrc versionado.
&lt;/h4&gt;

&lt;p&gt;Para gerar o authToken você pode usar o comando abaixo:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo -n 'registryuser:registrypassword' | openssl base64&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Com o authToken em mãos, basta criar o arquivo como no modelo abaixo:&lt;/p&gt;


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

&lt;p&gt;registry=&lt;a href="https://meu.dominio/repository/npm-group" rel="noopener noreferrer"&gt;https://meu.dominio/repository/npm-group&lt;/a&gt;&lt;br&gt;
always-auth=true&lt;br&gt;
_auth=bWF0ZXVzLm1hbGFxdWlhczoxMjM0NTY=&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Bônus: Usando Jenkins com Nexus&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Se você assim como eu, possui um Jenkins privado e deseja que o teu fluxo de publicação seja automatizado. O código abaixo possui o mínimo necessário para publicar nossas libs usando o Jenkins.&lt;/p&gt;


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

&lt;p&gt;pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    tools{nodejs "node”}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;environment {
    REGISTRY_URL = "http://localhost:8081/repository/malaquias-npm-private/“
    REGISTRY_USER_EMAIL = "malaquiasdev@gmail.com”
    NPM_TOKEN = "bnBtdXNlcjpWbnRlaG1fMDU=“
}

stages {
    stage('Git Checkout') {
        steps {
            git 'https://gitlab.com/malaquiasdev/nexus-study.git'
        }
    }

    stage('Publish to Nexus') {
        steps {
            sh ‘ls'
            sh 'echo -e "registry=${REGISTRY_URL}\nemail=${REGISTRY_USER_EMAIL}\nalways-auth=true\n_auth=${NPM_TOKEN}" &amp;amp;gt;&amp;amp;gt; .npmrc’
            sh 'npm publish'
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusão&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Nesse artigo pincelei um fluxo básico de como publicar e consumir libs privadas usando o Nexus Repository.&lt;/p&gt;




&lt;h2&gt;
  
  
  Finalizando...
&lt;/h2&gt;

&lt;p&gt;Se você gostou desse post, por favor não deixe de dar um like e compartilhar 😄&lt;/p&gt;

&lt;p&gt;Se quiser saber o que ando fazendo por ai ou tirar alguma dúvida fique a vontade para me procurar nas redes sociais como @ &lt;a href="https://twitter.com/malaquiasdev" rel="noopener noreferrer"&gt;malaquiasdev&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Para ler mais post meus acesse &lt;a href="http://malaquias.dev/" rel="noopener noreferrer"&gt;MalaquiasDEV | A Vida, o código e tudo mais&lt;/a&gt; .&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
      <category>devops</category>
    </item>
    <item>
      <title>O Guia dos Serverless das Galáxias #3 - Entendendo o ciclo de vida de uma função lambda</title>
      <dc:creator>Mateus Malaquias</dc:creator>
      <pubDate>Tue, 05 May 2020 13:16:03 +0000</pubDate>
      <link>https://dev.to/collabcode/o-guia-dos-serverless-das-galaxias-3-entendendo-o-ciclo-de-vida-de-uma-funcao-lambda-3jac</link>
      <guid>https://dev.to/collabcode/o-guia-dos-serverless-das-galaxias-3-entendendo-o-ciclo-de-vida-de-uma-funcao-lambda-3jac</guid>
      <description>&lt;p&gt;Quando a gente cria ou atualiza uma função, na maioria dos casos, esse processo é muito rápido e as nossas funções estão prontas para executar quase que imediatamente. &lt;/p&gt;

&lt;p&gt;No entanto, existem situações em que esses processos podem levar mais tempo.&lt;/p&gt;

&lt;p&gt;Neste post, vamos entender os estados de uma função, as condições de cada estado e como ocorre a transição entre eles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estados de uma função
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pendente
&lt;/h3&gt;

&lt;p&gt;É o primeiro estado pelo qual todas as funções passam quando são criadas. A função se mantém nesse estado durante um processo de deploy ou durante a configuração de todos os recursos externos necessários. &lt;/p&gt;

&lt;p&gt;Tenha sempre em mente que só é possível executar uma função quando o seu estado é &lt;strong&gt;Ativo&lt;/strong&gt;, portanto, qualquer invocação nesse momento irá falhar. &lt;/p&gt;

&lt;h3&gt;
  
  
  Ativo
&lt;/h3&gt;

&lt;p&gt;Alcançado após a conclusão de qualquer deploy com sucesso, configuração ou alocação de recursos durante a criação ou atualização de uma função. &lt;/p&gt;

&lt;p&gt;É importante ter em mente que as funções só podem ser invocadas nesse estado. Por isso que durante uma atualização, o estado permanece como ativo. &lt;/p&gt;

&lt;p&gt;Durante um processo de atualização todas as invocações irão ser executadas utilizando os códigos e as configurações anteriores até que o processo seja concluído com sucesso.&lt;/p&gt;

&lt;h3&gt;
  
  
  Falha
&lt;/h3&gt;

&lt;p&gt;É o estado que representa algo que deu errado na configuração ou no provisionamento de recursos externos.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inativo
&lt;/h3&gt;

&lt;p&gt;Inativo, onde acontece o famoso "cold start" é o estado de uma função quando ela fica sem ser executada por um determinado período de tempo ou quando a função precisa escalar rapidamente para atender muitas chamadas concorrentes. &lt;/p&gt;

&lt;p&gt;Esse estado existe para baratear os custos de infraestrutura do serviços, quando a função entra nesse estado todos os recursos externos que foram configurados para ela são removidos. &lt;/p&gt;

&lt;h2&gt;
  
  
  Estados de uma função durante uma atualização
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Em progresso
&lt;/h3&gt;

&lt;p&gt;Significa que uma atualização está acontecendo. Enquanto uma função está nesse sub estado, todas as invocação são realizadas nos códigos e configurações já existentes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bem sucedido
&lt;/h3&gt;

&lt;p&gt;A atualização foi concluída.&lt;/p&gt;

&lt;h3&gt;
  
  
  Falhou
&lt;/h3&gt;

&lt;p&gt;A atualização da função falhou, todas as alterações são abortadas. Tanto o código como a configuração anterior permanecem no estado ativo e disponíveis.&lt;/p&gt;

&lt;p&gt;Outro ponto importante durante o processo é que as funções só podem ser atualizadas se estiverem no estado &lt;strong&gt;Ativo&lt;/strong&gt; ou &lt;strong&gt;Inativo&lt;/strong&gt;. Os comandos de atualização emitidos nas funções que não estão nesses estados falharão.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ciclos de Vida dos Estados de uma função
&lt;/h2&gt;

&lt;p&gt;Como não conseguimos mover manualmente uma função entre os seus estados, a transição entre os estados acaba dependendo das ações que executamos diretamente sobre as funções.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmxw2tgnsiilkruk2cz2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmxw2tgnsiilkruk2cz2o.png" alt="Fluxograma do ciclo de vida de uma função" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Para todas as funções, o ciclo de vida do estado primário se parece com o seguinte:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Ao criar uma função, ela começa no estado &lt;strong&gt;Pendente&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;  Após a configuração de todos os recursos necessários com sucesso, o estado passa a ser &lt;strong&gt;Ativo&lt;/strong&gt;;

&lt;ul&gt;
&lt;li&gt;  Se a configuração de recurso ou função falhar por qualquer motivo, ela passará para o estado de &lt;strong&gt;Falha&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  Se uma função não for executado durante um período de tempo, ela entrará no estado &lt;strong&gt;Inativo&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;  Na primeira chamada após ficar &lt;strong&gt;Inativo&lt;/strong&gt;, uma função entra novamente no estado &lt;strong&gt;Pendente&lt;/strong&gt;;

&lt;ul&gt;
&lt;li&gt;  Êxito define o estado como &lt;strong&gt;Ativo&lt;/strong&gt; novamente;&lt;/li&gt;
&lt;li&gt;  Falha define o estado de volta para &lt;strong&gt;Inativo&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  Uma atualização com sucesso, também define o estado de volta para &lt;strong&gt;Ativo&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ciclo de vida de uma função durante o processo de atualização
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv9zfupee8pgt7xzx7kgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv9zfupee8pgt7xzx7kgj.png" alt="Fluxograma do ciclo de vida de uma função durante o processo de atualização" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Para atualizar funções, o ciclo de vida é o seguinte:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Na atualização, o estado de atualização é definido como &lt;strong&gt;Em Progresso&lt;/strong&gt;;

&lt;ul&gt;
&lt;li&gt;  Êxito define o estado como &lt;strong&gt;Bem Sucedido&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;  Uma falha define como &lt;strong&gt;Falha&lt;/strong&gt; mesmo;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  Uma função &lt;strong&gt;inativa&lt;/strong&gt; voltará ao estado ativo com uma atualização &lt;strong&gt;bem sucedida&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Na AWS (provedor de cloud que tenho mais contato) todas as funções mostrarão apenas um estado &lt;strong&gt;Ativo&lt;/strong&gt; no painel web. Você não verá uma transição de estado para &lt;strong&gt;Pendente&lt;/strong&gt; por exemplo. Mas dá para consultar o estado atual da função usando os SDKs da AWS e a CLI da AWS mais recentes (versão 1.16.291 ou superior).&lt;/p&gt;




&lt;h2&gt;
  
  
  Finalizando…
&lt;/h2&gt;

&lt;p&gt;Se você gostou desse post não esquece de dar um like e compartilhar 😄&lt;/p&gt;

&lt;p&gt;Se quiser saber o que ando fazendo por ai ou tirar alguma dúvida fique a vontade para me procurar nas redes sociais como @ &lt;a href="https://twitter.com/malaquiasdev"&gt;malaquiasdev&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Para ler mais post meus acesse &lt;a href="http://malaquias.dev"&gt;MalaquiasDEV | A Vida, o código e tudo mais&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
