<?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: Nathan B Hankes</title>
    <description>The latest articles on DEV Community by Nathan B Hankes (@nbhankes).</description>
    <link>https://dev.to/nbhankes</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%2F312370%2F71bcf6d0-72c5-403d-8b94-9044db4f7311.png</url>
      <title>DEV Community: Nathan B Hankes</title>
      <link>https://dev.to/nbhankes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nbhankes"/>
    <language>en</language>
    <item>
      <title>Getting Started With C#: Interfaces</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Wed, 19 Jul 2023 15:23:16 +0000</pubDate>
      <link>https://dev.to/nbhankes/getting-started-with-c-interfaces-2h4o</link>
      <guid>https://dev.to/nbhankes/getting-started-with-c-interfaces-2h4o</guid>
      <description>&lt;p&gt;This article is part of a series. For part one, visit the link below:&lt;br&gt;
&lt;a href="https://dev.to/nbhankes/getting-started-with-c-classes-objects-and-namespaces-1dgk"&gt;Part 1: Getting Started with C#: Classes, Objects, and Namespaces&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In C#, an interface specifies a set of methods, properties, events, or indexers (collectively referred to as class members) that a class &lt;em&gt;must&lt;/em&gt; define. This programmatic obligation is referred to as a contract. The interface contract functionally serves as a blueprint that classes must adhere to, ensuring consistent behavior, enabling polymorphism (we'll get more into this later), and providing a host of other benefits. &lt;/p&gt;

&lt;p&gt;To apply an interface, a class must use the :InterfaceName syntax after the class name. In the example below, you'll see the Truck and Car class names followed by :IVehicle. This means that both of these classes are bound to the IVehicle interface contract. By implementing :IVehicle on these classes, the class enters into a contract that promises to define the members stipulated by the IVehicle interface.&lt;/p&gt;

&lt;p&gt;Continuing with our example from &lt;a href="https://dev.to/nbhankes/getting-started-with-c-classes-objects-and-namespaces-1dgk"&gt;Part 1&lt;/a&gt; here's an interface and its implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;VehicleInventory&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IVehicle&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Year&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;

        &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IVehicle&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Year&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Car engine is started."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Car oil checked."&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Truck&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IVehicle&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Year&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Truck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Truck engine is started."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Truck oil checked."&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll notice that the IVehicle interface is implemented with the interface keyword. The interface does not provide any implementation details. It only defines members. The classes that implement this interface must provide implementations for all the members defined in the interface (in our case, methods and properties). This is why the Car class and the Truck class both have StartEngine() and CheckOil() method implementations. And this is why they both have the Make, Model, and Year properties defined.&lt;/p&gt;

&lt;p&gt;By separating the interface from the class implementation, we create a clear distinction between the contract and the actual implementation. While it may require writing additional code in each class that implements an interface, the benefits of code organization, reusability, flexibility, and testability outweigh the initial effort. Let's take a look at some of these benefits below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Using Interfaces
&lt;/h2&gt;

&lt;p&gt;Implementing methods individually in each class may seem like more work initially, but it serves an important purpose and offers several advantages:&lt;/p&gt;

&lt;h4&gt;
  
  
  Contract Enforcement
&lt;/h4&gt;

&lt;p&gt;As already discussed, interfaces provide a way to enforce a contract or agreement between classes. By implementing an interface, a class commits to providing specific methods or functionality defined by the interface. This ensures that all implementing classes adhere to the same set of behaviors.&lt;/p&gt;

&lt;h4&gt;
  
  
  Polymorphism
&lt;/h4&gt;

&lt;p&gt;Interfaces enable polymorphism, allowing objects of different classes to be treated interchangeably. This flexibility is valuable when writing code that works with multiple types of objects based on a shared set of methods. For example, you can create a collection of vehicles (objects implementing the IVehicle interface) and perform common actions on them without worrying about the specific class. Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;VehicleInventory&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;IVehicle&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Honda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Civic"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2022&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;IVehicle&lt;/span&gt; &lt;span class="n"&gt;truck&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Truck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ford"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"F-150"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="nf"&gt;PerformVehicleActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;PerformVehicleActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;truck&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;PerformVehicleActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IVehicle&lt;/span&gt; &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Make: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Make&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Model: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Year: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Year&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Main method above, we create instances of Car and Truck and assign them to variables of type IVehicle. This allows us to treat both objects polymorphically.&lt;/p&gt;

&lt;p&gt;The PerformVehicleActions method takes an IVehicle parameter and prints the vehicle details, starts the engine, checks the oil, and adds a line break for separation.&lt;/p&gt;

&lt;p&gt;Because the IVehicle interface guarantees the Make, Model, Year, StartEngine(), and CheckOil(), the PerformVehicleActions method can treat the Truck and Car classes the same.&lt;/p&gt;

&lt;h4&gt;
  
  
  Loose Coupling and Flexibility
&lt;/h4&gt;

&lt;p&gt;Using interfaces reduces tight coupling between classes. Instead of depending on specific class implementations, you can depend on the interface. This promotes better separation of concerns and improves the flexibility of your code. You can easily introduce new classes that implement the interface or modify existing classes without affecting the rest of the codebase.&lt;/p&gt;

&lt;p&gt;Let's say we want to add a new class to identify a new vehicle type. In the example below, we'll create a new Motorcycle class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Motorcycle&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IVehicle&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Year&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Motorcycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Motorcycle engine is started."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Motorcycle oil checked."&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;With the addition of the Motorcycle class, we can now create instances of Motorcycle and pass them to the PerformVehicleActions method defined in our polymorphism example above -- without modifying the PerformVehicleActions method itself. This showcases the flexibility provided by the interface, as the existing code can seamlessly work with the new Motorcycle class without any breaking changes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing and Mocking
&lt;/h4&gt;

&lt;p&gt;Interfaces help facilitate unit testing and mocking. You can create mock implementations of interfaces during testing to isolate and verify the behavior of specific components without relying on actual implementations. This helps in writing robust and maintainable tests.&lt;/p&gt;

&lt;p&gt;The interface implementation in the provided example facilitates testing and mocking by allowing the creation of test doubles or mock objects that implement the IVehicle interface. This enables isolated unit testing and the ability to simulate different scenarios without relying on the actual concrete implementations of Car and Truck. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Moq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Xunit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;VehicleInventory.Tests&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VehicleTests&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;PerformVehicleActions_Car_StartEngineAndCheckOilCalled&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Arrange&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;carMock&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Mock&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IVehicle&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
            &lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Make&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Honda"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Civic"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Year&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2022&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;vehicleActions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;VehicleActions&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="c1"&gt;// Act&lt;/span&gt;
            &lt;span class="n"&gt;vehicleActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PerformVehicleActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Assert&lt;/span&gt;
            &lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Once&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;carMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Once&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="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;PerformVehicleActions_Truck_StartEngineAndCheckOilCalled&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Arrange&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;truckMock&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Mock&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IVehicle&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
            &lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Make&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ford"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"F-150"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Year&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;vehicleActions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;VehicleActions&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="c1"&gt;// Act&lt;/span&gt;
            &lt;span class="n"&gt;vehicleActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PerformVehicleActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Assert&lt;/span&gt;
            &lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Once&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;truckMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CheckOil&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Once&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="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, we use the Moq mocking framework and the xUnit testing framework to demonstrate testing and mocking with the interface implementation. We create two test methods: PerformVehicleActions_Car_StartEngineAndCheckOilCalled and PerformVehicleActions_Truck_StartEngineAndCheckOilCalled.&lt;/p&gt;

&lt;p&gt;In each test method, we create a mock object of the IVehicle interface using Mock. We set up the necessary properties (Make, Model, and Year) for the mock objects to return specific values during the test.&lt;/p&gt;

&lt;p&gt;Next, we instantiate the VehicleActions class, which contains the PerformVehicleActions method that we want to test. We pass the mock object (carMock.Object or truckMock.Object) to the PerformVehicleActions method.&lt;/p&gt;

&lt;p&gt;Finally, we use the Verify method provided by the mock objects to assert that the StartEngine and CheckOil methods are called exactly once during the execution of the PerformVehicleActions method.&lt;/p&gt;

&lt;p&gt;By creating mock objects that implement the IVehicle interface, we can isolate the behavior being tested and verify that the expected methods are called, without relying on the actual implementations of Car and Truck. This enables effective unit testing and helps identify issues in the VehicleActions class while maintaining test independence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Interfaces to Your Codebase
&lt;/h2&gt;

&lt;p&gt;Interfaces are typically organized into namespaces alongside classes and other related interfaces. Remember from part one, a namespace is a container for organizing related types, such as classes and interfaces. It helps prevent naming conflicts and provides a logical structure to your code.&lt;/p&gt;

&lt;p&gt;When it comes to storing interfaces in your codebase, there is no universally prescribed folder structure or naming convention. However, it's generally recommended to follow a structure that reflects the logical organization of your codebase and promotes maintainability. Here are some suggestions:&lt;/p&gt;

&lt;p&gt;Create a separate folder or directory for interfaces: You can have a dedicated folder specifically for interfaces, which can make it easier to locate and manage them.&lt;/p&gt;

&lt;p&gt;Use meaningful and descriptive names: Name your interfaces based on the functionality they represent. Make sure the names are clear and indicative of their purpose.&lt;/p&gt;

&lt;p&gt;Group related interfaces together: If you have interfaces that are closely related, you can place them in the same folder or subfolder. This makes it easier for developers to find related interfaces when working on a specific feature or module.&lt;/p&gt;

&lt;p&gt;Follow a consistent naming convention: It's good practice to follow a consistent naming convention for interfaces, such as prefixing them with "I" (e.g., IExampleInterface). This convention helps distinguish interfaces from classes and makes your code more readable.&lt;/p&gt;

&lt;p&gt;Below is an example from the open source &lt;a href="https://github.com/nopSolutions/nopCommerce"&gt;nopCommerce repository&lt;/a&gt;. You'll notice the interface files (staring with capital I) are in the same folder as the class files. In the External folder, all classes and interfaces are built inside of the namespace Nop.Services.Authentication.External:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6oVf3iLN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77deezvkkzjsgk7w66ib.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6oVf3iLN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77deezvkkzjsgk7w66ib.PNG" alt="Image description" width="435" height="679"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ultimately, the specific folder structure and naming conventions will depend on your project's requirements and the preferences of your development team. The key is to ensure consistency and maintainability throughout your codebase.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting Started with C#: Classes, Objects, and Namespaces</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Sun, 18 Jun 2023 01:40:54 +0000</pubDate>
      <link>https://dev.to/nbhankes/getting-started-with-c-classes-objects-and-namespaces-1dgk</link>
      <guid>https://dev.to/nbhankes/getting-started-with-c-classes-objects-and-namespaces-1dgk</guid>
      <description>&lt;p&gt;Together, classes, objects, and namespaces form the fundamental building blocks of C# programs. This article offers a brief orientation to each of these.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Classes and Objects
&lt;/h2&gt;

&lt;p&gt;Classes are the building blocks of Object-Oriented Programming, serving as blueprints or templates for creating objects. Objects, on the other hand, are instances of classes that represent real-world entities or concepts.&lt;/p&gt;

&lt;p&gt;For example, a Car class will define the blueprint for creating car objects. The Car class may have properties like make, model, and year, as well as methods such as StartEngine() and Drive().&lt;/p&gt;

&lt;p&gt;This is what the Car class would look like in your codebase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//Fields&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;//A field is a variable declared within a class.&lt;/span&gt;



    &lt;span class="c1"&gt;//Properties&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Year&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//A property is a class member that offers a convenient way to&lt;/span&gt;
    &lt;span class="c1"&gt;//access, modify, or calculate the value of a private field.&lt;/span&gt;
    &lt;span class="c1"&gt;//The get and set keywords are used to define the accessors&lt;/span&gt;
    &lt;span class="c1"&gt;//for the property. The get accessor returns the property&lt;/span&gt;
    &lt;span class="c1"&gt;//value, and the set accessor assigns a new value to the &lt;/span&gt;
    &lt;span class="c1"&gt;//property&lt;/span&gt;



    &lt;span class="c1"&gt;// Class Constructor&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="c1"&gt;//A Class Constructor is a special member method responsible&lt;/span&gt;
     &lt;span class="c1"&gt;//for initializing the object of that class.&lt;/span&gt;



    &lt;span class="c1"&gt;// Method 1&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The engine is started."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Method 2&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The vehicle is driving."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//A method is a block of code within a class that performs a&lt;/span&gt;
    &lt;span class="c1"&gt;//specific task or action. Methods are declared within a class&lt;/span&gt;
    &lt;span class="c1"&gt;//and are accessed by and invoked on objects created from that&lt;/span&gt;
    &lt;span class="c1"&gt;//class. &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's say you create two car objects: car1 and car2. These objects are instances of the Car class and represent real-world cars. Each car object will have its own set of property values.&lt;/p&gt;

&lt;p&gt;For example, car1 may have the make "Toyota," model "Camry," and year "2012," while car2 may have the make "Honda," model "Accord," and year "2020."&lt;/p&gt;

&lt;p&gt;This is what instantiating those two Car objects would look like in your codebase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Car&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Camry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2012&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Car&lt;/span&gt; &lt;span class="n"&gt;car2&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Honda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Accord"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2020&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By instantiating car objects from the Car class, you can work with each car individually, accessing their properties and invoking their methods. You can start the engine of car1 by calling the StartEngine() method on the car1 object, and similarly, you can drive car2 by invoking the Drive() method on the car2 object. Calling the Car class methods on your Car objects looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each car object maintains its own state and behavior, allowing you to perform different operations on different cars. Meaning you can modify the properties of car1 without affecting the properties of car2, and vice versa.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Namespaces
&lt;/h2&gt;

&lt;p&gt;Classes are held within namespaces. By organizing classes within a namespace, developers create a clear and logical grouping of related code elements.&lt;/p&gt;

&lt;p&gt;This is what that a namespace would look like in your codebase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;VehicleInventory&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Car class code from above&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Truck&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="c1"&gt;// Truck class&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Motorcycle&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="c1"&gt;// Motorcycle class&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;Namespaces must be imported into your file with a using statement, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;VehicleInventory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Now the Car class can be used directly&lt;/span&gt;
&lt;span class="n"&gt;Car&lt;/span&gt; &lt;span class="n"&gt;car3&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Prius"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2018&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;car3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartEngine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This has been a brief orientation to the structure of a C# program. In my next article, I will provide an orientation to Interfaces:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/nbhankes/getting-started-with-c-interfaces-2h4o"&gt;Part 2: Getting Started With C#: Interfaces&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>webdev</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Financial App Design: CSS Considerations</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Sun, 08 Aug 2021 05:11:17 +0000</pubDate>
      <link>https://dev.to/nbhankes/financial-app-design-css-considerations-3bjl</link>
      <guid>https://dev.to/nbhankes/financial-app-design-css-considerations-3bjl</guid>
      <description>&lt;p&gt;When your app involves handling a user's money, any minor issue with user experience or design will shake their confidence in your product. If you can't get design right, how do you expect your customers to trust the security of their money?&lt;/p&gt;

&lt;p&gt;Let's consider the use case where you're brought into a contract position for a financial app that already exists. The functionality is already in place, so you don't have much control on high level user experience (onboarding flow, navigation, etc.) Your role isn't to design the pages from scratch or anything like that. You're strictly there to make them look nice with some CSS and minor changes to the HTML here and there.&lt;/p&gt;

&lt;p&gt;I'll assume you already have a grasp of the UX fundamentals, but I will touch on these as they relate specifically to a financial app.&lt;/p&gt;

&lt;p&gt;Here is a brief list of considerations before you go digging into the stylesheets.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. ) Show Users What They Want
&lt;/h2&gt;

&lt;p&gt;There is a reason your user is on a specific page. They're looking for certain information or want to perform an action. If it's account balances they're after, make sure the numbers displayed are prominent enough that it's the first thing the user's eye naturally gravitates to. And if it's an action they need to take, make sure the button or call to action pops off the screen. Bold colors and drop shadows can help here.&lt;/p&gt;

&lt;p&gt;In the example by &lt;a href="https://dribbble.com/shots/10679788-Financial-Mobile-App"&gt;HIX&lt;/a&gt; below, notice where your eyes go first. Do they go to the numbers or colors?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kLyETp_c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8x3qo0qn7syru9pzd6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kLyETp_c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8x3qo0qn7syru9pzd6e.png" alt="Financial app design should be minimal without being bland" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2.) Less is More
&lt;/h2&gt;

&lt;p&gt;Minimalism is in, but bland is not. So if you're only authorized to use bland (AKA safe) colors, there should be some other interesting elements to keep the user's attention. Depending on the brand personality, this can range from subtle animations that reassure your user that some process just completed successfully to modern dashboard design that includes design like layering, drop shadows, rounded edges, transparent backdrops, etc. When you're designing for mobile, it's important not to go too wild here since these design choices can impact performance in lower bandwidth use cases.&lt;/p&gt;

&lt;p&gt;In the example below, the designer &lt;a href="https://dribbble.com/shots/11316739-Financial-application"&gt;Mira&lt;/a&gt; creates a beautiful dashboard in grayscale.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  3. ) Get Your Input Mode Right
&lt;/h2&gt;

&lt;p&gt;The HTML input tag attribute of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode"&gt;inputmode&lt;/a&gt; is supported by all mobile browsers. Do you know exactly what your user will input? Why distract them with any unnecessary keyboard elements?&lt;/p&gt;

&lt;p&gt;Take a look at the below infographic by &lt;a class="mentioned-user" href="https://dev.to/stefanjudis"&gt;@stefanjudis&lt;/a&gt;. If the input was for the amount stated on a check, for instance, what inputmode could you use?&lt;/p&gt;

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

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

&lt;p&gt;While coming into a project that's already designed can feel limiting, there's plenty of value you can add working with CSS alone. Just stay laser focused on why your user is on a page, and your knowledge of the UX fundamentals can take you far.&lt;/p&gt;

&lt;p&gt;If you have a financial app design project coming up, visit these for some inspiration:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.muz.li/top-10-banking-app-ui-design-case-study-41ebc45ded1c"&gt;Top 10 Banking Apps UI/UX Design Case Studies&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dribbble.com/search/banking"&gt;Banking on Dribble&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dribbble.com/search/investing"&gt;Investing on Dribble&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to your phone and computer to study the financial apps and websites you use. What works well? Why does it work?&lt;/p&gt;

</description>
      <category>ux</category>
    </item>
    <item>
      <title>The API Series - Part 4: Updating Your GitHub Status With a GraphQL Mutation</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Thu, 13 May 2021 12:36:16 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-api-series-part-4-updating-your-github-status-with-a-graphql-mutation-57bm</link>
      <guid>https://dev.to/vetswhocode/the-api-series-part-4-updating-your-github-status-with-a-graphql-mutation-57bm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you'll learn about GraphQL mutations, authorization, and get a step-by-step demonstration of how to change you GitHub status sending a mutation request to the GitHub GraphQL API.&lt;/p&gt;

&lt;p&gt;If you missed the other parts to this API series, you can find the rest at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/vetswhocode/the-api-series-part-1-an-intro-to-apis-1bd"&gt;Part 1 - An Intro to APIs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-api-series-part-2-the-rest-api-fetch-and-axios-lf"&gt;Part 2 - The REST API, fetch(), and AXIOS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-api-series-graphql-and-sending-queries-with-fetch-gf0"&gt;Part 3 - GraphQL and Sending Queries With fetch()&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Some familiarity with HTML, Git, and Javascript. &lt;/p&gt;
&lt;h2&gt;
  
  
  What Is A GraphQL Mutation
&lt;/h2&gt;

&lt;p&gt;A GraphQL mutation changes data in an API database. Mutations encompass the REST API POST, PUT, PATCH, and DELETE methods. These GraphQL mutations are defined by the API and will often require some form of authorization to complete.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started With Your First Mutation
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;APIs can change over time, so please take the time to study  the &lt;a href="https://docs.github.com/en/graphql" rel="noopener noreferrer"&gt;GitHub GraphQL API documentation&lt;/a&gt; should you encounter any &lt;br&gt;
issues if you are reading this tutorial far out from its &lt;br&gt;
publication date. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this tutorial, you'll be learning about mutations in the context of the &lt;a href="https://docs.github.com/en/graphql" rel="noopener noreferrer"&gt;GitHub GraphQL API&lt;/a&gt;. In order to gain insight into what types of data the API allows us to change, we'll have to reference the API documentation for a list of mutations. By navigating to the &lt;a href="https://docs.github.com/en/graphql/reference/mutations" rel="noopener noreferrer"&gt;Mutation Reference&lt;/a&gt; page, we encounter a list of all the mutations allowed by the API. &lt;br&gt;
In this tutorial, we're going to use the fetch() method to update our user status. The mutation allowing this behavior is called &lt;a href="https://docs.github.com/en/graphql/reference/mutations#changeuserstatus" rel="noopener noreferrer"&gt;changeUserStatus&lt;/a&gt; and is described by the Mutation Reference documentation like so:&lt;br&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%2Ff101i3e06lnq4hzblhsh.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff101i3e06lnq4hzblhsh.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see two clearly defined fields listed: The Input fields and the Return fields.&lt;/p&gt;
&lt;h3&gt;
  
  
  Input fields
&lt;/h3&gt;

&lt;p&gt;Input fields are the inputs the API will accept for this particular mutation. We will include these input fields and values in our mutation request so that the API knows what fields to update and what values to update them to. The &lt;a href="https://docs.github.com/en/graphql/reference/input-objects#changeuserstatusinput" rel="noopener noreferrer"&gt;ChangeUserStatusInput!&lt;/a&gt; object provides the fields we can change, as seen below:&lt;br&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%2Fgptskizb3m6ti6lfb3dh.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgptskizb3m6ti6lfb3dh.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above photo, we see a list of all the inputs the changeUserStatus mutation will accept. These include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clientMutationId
emoji
expiresAt
limitedAvailability
message
organizationId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The input name column also includes the type of data the input field expects to receive: String, DateTime, Boolean, ID, etc. And the description columns provides further details, such as whether the input is required for a successful mutation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Return fields
&lt;/h3&gt;

&lt;p&gt;Return fields represent the data that the changeUserStatus mutation returns after completion. In this way, every GraphQL mutation is also a query. This is ideal because we can immediately verify that our fields updated to match our input fields or update them on the user's screen in real time. This mutation returns the following data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clientMutationId
status {
    UserStatus {
        createdAt
        emoji
        emojiHTML
        expiresAt
        id
        indicatesLimitedAvailability
        message
        organization
        updatedAt
        user {
            User {
                A list of all the User fields...
                }
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While the changeUserStatus Return field documentation lists two rows, the status row accepts the UserStatus object, which has several of its own fields. And the user field points toward another object, and so on. To keep your project load times as fast as possible, it's good practice to only return what is needed. In this example, we'll be returning the following fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clientMutationId
status {
     message
     emoji
     updatedAt
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Writing Your First GraphQL Mutation
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.github.com/en/graphql/guides/forming-calls-with-graphql" rel="noopener noreferrer"&gt;GitHub GraphQL API documentation&lt;/a&gt; tells us exactly what is required to make a successful mutation. &lt;a href="https://graphql.org/learn/" rel="noopener noreferrer"&gt;The GraphQL Foundation&lt;/a&gt; website provides additional documentation regarding the GraphQL syntax and conventions. From GitHub's guide "&lt;a href="https://docs.github.com/en/graphql/guides/forming-calls-with-graphql" rel="noopener noreferrer"&gt;Forming Calls with GraphQL&lt;/a&gt;," the following components are required to complete a successful GraphQL mutation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mutation name. The type of modification you want to perform.&lt;/li&gt;
&lt;li&gt;Input object. The data you want to send to the server, composed of input fields. Pass it as an argument to the mutation name.&lt;/li&gt;
&lt;li&gt;Payload object. The data you want to return from the server, composed of return fields. Pass it as the body of the mutation name.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So here's how our changeUserStatus mutation will look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    mutation {
        changeUserStatus(input: {clientMutationId: "YOUR_USERNAME", emoji: ":rocket:", expiresAt: "2021-05-09T00:00:00", limitedAvailability: true,  message:"Working on an API tutorial"}) {
                    clientMutationId
                    status {
                        message
                        emoji
                        updatedAt
                    }
            }    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code we have the mutation name of changeUserStatus, we have the Input object and the values we want to pass to it, and we also have the payload object, which consists of the return fields we previously decided on. This satisfies the three numbered components listed in GitHub's "Forming Calls with GraphQL" guide. In order to ensure that the above mutation is drafted correctly, we'll go into GitHub's &lt;a href="https://docs.github.com/en/graphql/overview/explorer" rel="noopener noreferrer"&gt;GraphQL API Explorer&lt;/a&gt; interface. This is a powerful tool that helps us ensure we're structuring our queries and mutations correctly. I added this mutation into the Explorer, inserting my username in the clientMutationId input filed value, and here's what I saw:&lt;/p&gt;

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

&lt;p&gt;The leftmost column contains the mutation, input fields and values, and the return fields. The center column displays what API response after clicking on the circular Play button in the top left corner. And the rightmost column provides the API documentation, which helps when drafting the mutation or query. And since the GitHub API Explorer requires user login, this mutation actually executes. The return fields are displaying the status listed on my profile. Success!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up The Project
&lt;/h2&gt;

&lt;p&gt;Before we can insert our mutation into a fetch() request, we'll need to generate a personal access token that creates scoped permissions and allows us to make changes to the GitHub API. Below is a step-by-step list of how to do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login into your GitHub account&lt;/li&gt;
&lt;li&gt;Click on your avatar in the top right corner&lt;/li&gt;
&lt;li&gt;Navigate to the "Settings" item
and click through&lt;/li&gt;
&lt;li&gt;Navigate to the "Developer Settings" item and click through&lt;/li&gt;
&lt;li&gt;Navigate to the "Personal access tokens" item and click through&lt;/li&gt;
&lt;li&gt;Click the "Generate new token" button. You'll be prompted to enter your password. Do it.&lt;/li&gt;
&lt;li&gt;Check the boxes setting the following permissions recommended by GitHub:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user
public_repo
repo
repo_deployment
repo:status
read:repo_hook
read:org
read:public_key
read:gpg_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Click the "Generate token" button. GitHub will generate the token, which will look like a string of random characters. Keep the window open for later use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So now we have our mutation formed and our authorization token available. We'll also need the GitHub GraphQL API URL, which is found in the GitHub GraphQL API documentation: &lt;code&gt;https://api.github.com/graphql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Okay, so now we're ready to dive into our editor of choice to make this mutation. In this example, we'll be creating an HTML and JS project and run the fetch request on our local system.&lt;/p&gt;

&lt;p&gt;The code used in this tutorial can be reviewed &lt;a href="https://github.com/nbhankes/JS-GraphQL-Mutation-Demo" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create two files inside of a new project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html
script.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy and paste the following code into the HTML file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;title&amp;gt;JS-GraphQL-Mutation-Demo&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;button type="text/javascript" onclick="myAlert()"&amp;gt;
      Check Script Connection
    &amp;lt;/button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we've set up a standard HTML document, linked our &lt;code&gt;script.js&lt;/code&gt; file, and created a button that will execute a function called &lt;code&gt;myAlert()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now in our &lt;code&gt;script.js&lt;/code&gt; file, insert our &lt;code&gt;myAlert()&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myAlert() {
    alert("Documents Successfuly Connected!");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code is designed to verify that our index.html and script.js are in fact connected. It's not required, but gives us confidence and ensures we don't waste time troubleshooting this later on.&lt;/p&gt;

&lt;p&gt;To execute the function, run the project using an extension like &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live Server&lt;/a&gt;. Click the "Check Script Connection" button on the browser. If the files are connected, you'll see an alert pop up that reads "Documents Successfully Connected!"&lt;/p&gt;

&lt;p&gt;So our project foundation is set, and we can begin crafting our fetch statement. We'll pass the mutation, the API URL, and the fetch options to our fetch as variables. So let's create the variables like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mutation = `
    mutation {
        changeUserStatus(input: {clientMutationId: "YOUR_USERNAME", emoji: ":rocket:", expiresAt: "2021-05-09T00:00:00", limitedAvailability: true,  message:"Working on API tutorial"}) {
                    clientMutationId
                    status {
                        message
                        emoji
                        updatedAt
                    }
            }    
        }
                `;


const url = "https://api.github.com/graphql";


let opts = {
    method: "POST",
    headers: { "Content-Type": "application/json", "Authorization": "Bearer PERSONAL_ACCESS_TOKEN" },
    body: JSON.stringify({query: mutation })
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this phase, you'll want to replace "YOUR_USERNAME" and "PERSONAL_ACCESS_TOKEN" with the actual values you want to use. We already generated the personal access token in GitHub, so copy that value and replace the &lt;code&gt;PERSONAL_ACCESS_TOKEN&lt;/code&gt; string with the token. Your &lt;code&gt;USER_NAME&lt;/code&gt; is your GitHub user name. You'll also want to adjust the expiresAt input variable to some time in the future.&lt;/p&gt;

&lt;p&gt;Next, we'll pass the variables to our fetch, which will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, opts)
  .then(res =&amp;gt; res.json())
  .then(console.log)
  .catch(console.error);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now save your project and check the console in developer tools. The input values should be returned in the return fields. If you login to you GitHub account and navigate your profile, you'll see that the mutation worked:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmo937reuid34lwzkoef.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%2Fxmo937reuid34lwzkoef.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>javascript</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The API Series - Part 3: GraphQL and Sending Queries with fetch()</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Thu, 06 May 2021 12:57:56 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-api-series-graphql-and-sending-queries-with-fetch-gf0</link>
      <guid>https://dev.to/vetswhocode/the-api-series-graphql-and-sending-queries-with-fetch-gf0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial you'll learn how to query data from a GraphQL API. In the process, you'll be exposed to some common tools used to work with GraphQL APIs, GraphQL syntax and structure, and you'll receive a VanillaJS GraphQL repository to study and get running on your local system.&lt;/p&gt;

&lt;p&gt;If you missed the previous parts, you can find them here:&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-api-series-part-1-an-intro-to-apis-1bd"&gt;Part 1 - An Intro to APIs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-api-series-part-2-the-rest-api-fetch-and-axios-lf"&gt;Part 2 - The REST API, fetch(), and AXIOS&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Some familiarity with HTML, Git, and JavaScript. &lt;/p&gt;
&lt;h2&gt;
  
  
  What is GraphQL
&lt;/h2&gt;

&lt;p&gt;In the same way that the RESTful APIs conform to a REST architectural style, GraphQL APIs follow a strict GraphQL architecture. GraphQL is a query language for APIs organized with this GraphQL architecture. But unlike RESTful APIs, GraphQL has a single URL endpoint, offering an advantage over working with REST APIs that require different URL endpoints for different data. Additionally, GraphQL APIs only returns the data you need, unlike REST APIs which often deliver all the data associated with an object. For example, if you want to fetch the user name, the REST API would return the User object along with all of its properties. This is known as overfetching and can slow down your applications. With GraphQL, as you'll see, you can return the user name only.&lt;/p&gt;

&lt;p&gt;As a frontend developer, you'll be interacting with an API that is already built, but understanding how they're built is useful. The GraphQL schema architecture is defined by a series of schema based on type, like the below example from the &lt;a href="https://graphql.org/" rel="noopener noreferrer"&gt;GraphQL Foundation&lt;/a&gt; website:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hero&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Character&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Character&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
  &lt;span class="nx"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Character&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;homeWorld&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Planet&lt;/span&gt;
  &lt;span class="nx"&gt;species&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Species&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Planet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
  &lt;span class="nx"&gt;climate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Species&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
  &lt;span class="nx"&gt;lifespan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Int&lt;/span&gt;
  &lt;span class="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Planet&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, there are several types: Query, Character, Planet, and Species. Some types are built into the query language. Examples of these are the types Query and Mutation, which we'll dive into deeper later on. The custom types of Character, Planet, and Species are referred to as object types. Each type will have one or more properties, which are often referred to as fields. From the example above, the Query type has a field of hero, which returns an array of the Character object type. Within the API, fields are assigned a type, such as the built-in String, Int, Float, Boolean, or ID, or fields are assigned type objects, such as, in the example above, Character, Planet, or Species. Like the syntax of JavaScript, object types enclosed in brackets return an array of that object type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Queries and Mutations
&lt;/h2&gt;

&lt;p&gt;Whereas the REST API has several methods, such as POST, GET, PATCH, PUT, and DELETE, GraphQL has only two methods: Query and Mutation.&lt;/p&gt;

&lt;p&gt;Queries are like the REST API GET method. They return data stored by the API.&lt;/p&gt;

&lt;p&gt;Mutations change data, and encompass the REST API POST, PUT, PATCH, and DELETE methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started With GraphQL API Query
&lt;/h2&gt;

&lt;p&gt;In order to avoid getting bogged down in setting up a development environment to get started, we're going to first learn about consuming a GraphQL API using the OneGraph's GraphiQL explorer located at &lt;a href="https://www.onegraph.com/graphiql" rel="noopener noreferrer"&gt;https://www.onegraph.com/graphiql&lt;/a&gt; &lt;br&gt;
The home page will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fesqh2p4ikfm80j6awa6k.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%2Fesqh2p4ikfm80j6awa6k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OneGraph is a company that integrates all the most commonly used APIs in business into a single GraphQL API, so developers can query Twitter, Salesforce, Slack, and UPS in a single query. GraphiQL is not owned by OneGraph. It is a tool that you can use independently.&lt;/p&gt;

&lt;p&gt;To learn more about GraphiQL, visit &lt;a href="https://github.com/graphql/graphiql" rel="noopener noreferrer"&gt;https://github.com/graphql/graphiql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the leftmost column, we see all the APIs that OneGraph has integrated into their offering. The center columns is where we will write our query. The rightmost column is where our query output will be displayed.&lt;/p&gt;

&lt;p&gt;In the below example, we'll query the DEV blogging API to get some article information from user &lt;code&gt;nbhankes&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffy696dcixywrw4an01ct.gif" 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%2Ffy696dcixywrw4an01ct.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The GraphiQL explorer shows us the GraphQL API schema structure of the DEV API and allows us to select the data we'd like to retrieve from the API. As we make this selection, the explorer creates a query, which we see being built in the middle column. Once our query is built, we run the query by hitting the play button on the bar. The query is then sent to the DEV API and the results are displayed on the right.&lt;/p&gt;

&lt;p&gt;Below is the actual code for you to study. Notice the terms edges and node in the section labeled GraphQL Query.  nodes define objects and edges define relationships between objects and are optional (except in the Relay GraphQL client). Adding these to a query can be useful when working with complex APIs schemas. For the sake of this introduction, it's just important to be aware of them. If you'd like to dive deeper into edges and nodes, visit &lt;a href="https://www.apollographql.com/blog/explaining-graphql-connections-c48b7c3d6976/" rel="noopener noreferrer"&gt;https://www.apollographql.com/blog/explaining-graphql-connections-c48b7c3d6976/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's dive into the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//GraphQL Query&lt;/span&gt;

&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;MyQuery&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;devTo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nbhankes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;edges&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;title&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c1"&gt;//API Response&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;devTo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;articles&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;edges&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The API Series - Part 2: The REST API, fetch(), and AXIOS&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The API Series - Part 1: An Intro to APIs&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Classless CSS Isn't Trashy&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Upgrade Your CSS: The Syntax.fm Typography Sizing Strategy&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="p"&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="c1"&gt;//GraphQL Query without edges or node&lt;/span&gt;

&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;MyQuery&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;devTo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nbhankes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;title&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="c1"&gt;//API Response without edges or node&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;devTo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;articles&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The API Series - Part 2: The REST API, fetch(), and AXIOS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The API Series - Part 1: An Intro to APIs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Classless CSS Isn't Trashy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Upgrade Your CSS: The Syntax.fm Typography Sizing Strategy&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="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, you can see that the shape of the query defines the shape of the API response. The response is shaped like a nested JavaScript object and can be handled similarly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using GraphQL in Your Project: A Demo
&lt;/h2&gt;

&lt;p&gt;While the GraphiQL explorer is extremely useful, you can't just add the GraphQL query into your code and expect it to work. Below you'll find a link to a GitHub repo that makes a GraphQL query using plain JavaScript and the Fetch() API. This demonstration repository contains code for a website that queries the &lt;a href="https://api.spacex.land/graphql/" rel="noopener noreferrer"&gt;SpaceX GraphQL API&lt;/a&gt; and renders the response data to the browser. The demo built this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajpp3fk25fl3qsjahe1s.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%2Fajpp3fk25fl3qsjahe1s.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the great thing about working with APIs is that if the CEO of SpaceX changes, our website will automatically reflect the changes as soon as the API is updated.&lt;/p&gt;

&lt;p&gt;Visit the &lt;a href="https://vanillajs-graphql-demo.surge.sh/" rel="noopener noreferrer"&gt;Live Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Link To Repo: &lt;a href="https://github.com/nbhankes/vanillaJS-GraphQL-demo" rel="noopener noreferrer"&gt;https://github.com/nbhankes/vanillaJS-GraphQL-demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Study the comments and the code in the repository, follow the directions on the README.md file to get the project running on your local environment. Customize the query and template literal for practice.&lt;/p&gt;

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

&lt;p&gt;In this tutorial you learned how to query data from a GraphQL API. You were exposed to some common tools used to work with GraphQL APIs, the GraphQL syntax and structure, and you received a VanillaJS GraphQL repository to study and get running on your local system.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>javascript</category>
      <category>graphql</category>
    </item>
    <item>
      <title>The API Series - Part 2: The REST API, fetch(), and AXIOS</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Thu, 29 Apr 2021 13:41:05 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-api-series-part-2-the-rest-api-fetch-and-axios-lf</link>
      <guid>https://dev.to/vetswhocode/the-api-series-part-2-the-rest-api-fetch-and-axios-lf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you'll learn of different tooling options that allow you to make requests from APIs, you'll learn how to retrieve data from a REST API, how to submit data to a REST API, and you'll learn how to use a developer key in the case that the API requires it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Some familiarity with JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started With the REST API
&lt;/h2&gt;

&lt;p&gt;RESTful APIs communicate using HTTP/HTTPS. So part of your request will include what looks to be a website URL. These URLs are found in the API documentation, and they are the access points for the data or functionality you need. As an example, the following URL is part of a &lt;a href="https://docs.forem.com/api/" rel="noopener noreferrer"&gt;Dev.to API&lt;/a&gt; request to get the blog articles for a user named "vwc-user1": &lt;code&gt;https://dev.to/api/articles?username=vwc-user1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The API may also display the format of all the data associated within this URL. It looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxbuohgqt7jfo8n87f8sl.JPG" 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%2Fxbuohgqt7jfo8n87f8sl.JPG" alt="DEV API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This list and data is stored as JSON. JSON stands for JavaScript Object Notation. It is a lightweight format for storing and transporting data. But without formatting and parsing, it's not very useful to us. If you submit the URL to the browser using your username instead of "vwc-user1," you'll only see a jumble of data. &lt;/p&gt;

&lt;p&gt;To get our data in a way that's useful to use, we'll need to add in some tooling designed just for this purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fetch()
&lt;/h2&gt;

&lt;p&gt;Per the MDN Documentation:&lt;/p&gt;

&lt;p&gt;"The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt; provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch" rel="noopener noreferrer"&gt;fetch()&lt;/a&gt; method that provides an easy, logical way to fetch resources asynchronously across the network."&lt;/p&gt;

&lt;p&gt;The Fetch API is something that is already available to you. That's because the Fetch API is part of the browser software and certain Fetch objects are part of the Javascript language. It will just work.&lt;/p&gt;

&lt;p&gt;Before going further, you'll need to know the HTTP verbs. Below is a list of these verbs and what function they do when they are declared as your request method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST: Creates and inserts new data to API&lt;/li&gt;
&lt;li&gt;GET: Receive something from the API&lt;/li&gt;
&lt;li&gt;DELETE: Delete data&lt;/li&gt;
&lt;li&gt;PUT*: Updates/replaces existing data&lt;/li&gt;
&lt;li&gt;PATCH*: Updates/modifies existing data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*To understand the differences between PUT and PATCH, visit &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH" rel="noopener noreferrer"&gt;PATCH - HTTP | Mozilla Developer Network&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the sections below, we'll use the fetch() method to make a GET and POST request.&lt;/p&gt;

&lt;h2&gt;
  
  
  GET
&lt;/h2&gt;

&lt;p&gt;Let's say that we found our API endpoint already. This is the part that looks like a website URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;http://some-site.com//some.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is an example of a Fetch request to that same endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://some-site.com//some.json&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="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Request successful&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;text&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;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Request failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we invoke the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noopener noreferrer"&gt;fetch()&lt;/a&gt; method, passing it the URL shared above. Within the Fetch() method is also included the method type of "get" as an option within the Fetch() request. This is wrapped in curly brackets. The GET method retrieves data from the API. Other methods, which you'll see shortly, can send data to a database associated with the API.&lt;br&gt;
Second, we see a .then() chained to the fetch() method. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then" rel="noopener noreferrer"&gt;then()&lt;/a&gt; is part of JavaScript's Promises object. So once our Fetch() method delivers the desired resource, the promise is officially met and the Then() method executes a function. In this case, the function takes the response from API request, which Fetch() handles by returning as an object called "&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Response" rel="noopener noreferrer"&gt;response&lt;/a&gt;," and turns this raw data into text using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Body/text" rel="noopener noreferrer"&gt;Text()&lt;/a&gt; method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Oftentimes the &lt;a href="https://developer.mozilla.org/en-&amp;gt;US/docs/Web/API/Body/json" rel="noopener noreferrer"&gt;json()&lt;/a&gt; method is used in place of the Text() &amp;gt;method, and that's to convert the raw data within the response &amp;gt;object into a json object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once the request is turned to text, the next promise in our chain is met and the second Then() method executes a function. In this case, the Text() method returns a "text" object (an object created by this particular method) and logs the string "Request successful" and the text object to the console.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch" rel="noopener noreferrer"&gt;Catch()&lt;/a&gt; method is designed specifically for error handling and will execute a function that logs an error message when the previous promises are not met.&lt;/p&gt;
&lt;h2&gt;
  
  
  POST
&lt;/h2&gt;

&lt;p&gt;There are times when we want to send data to a database using an API. For example, the Twitter API allows developers to post tweets through API requests. When you send new data, this is considered the POST method. When you update existing data, this is what's known as a PUT method.&lt;/p&gt;

&lt;p&gt;In the example below, we are going to POST the user object to the API endpoint of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;https://example-api.com/post-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// this is our user object that we're passing to the API via POST request&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;example@email.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// this is our POST request&lt;/span&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example-api.com/post-user&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="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;X-API-KEY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-apikey-string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Accept&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&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="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; 
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we set the fetch method as POST to let the API know that we are passing it new data. The headers section allows us to include more instructions and information with our request. You'll notice an API X-API-Key included in the header. This allows the API to authenticate our request. In this case, we would have registered with &lt;a href="http://www.example-api.com" rel="noopener noreferrer"&gt;www.example-api.com&lt;/a&gt; to receive an API key. When they see a request from our unique API key, they'll know it's coming from the registered user with that key.&lt;/p&gt;

&lt;p&gt;Within the header section, you'll also notice "Accept" and "Content-Type." In this example, we're letting the API know to accept and expect to receive data in the "application/json" format. The application documentation should let you know how the API expects to receive data.&lt;/p&gt;

&lt;p&gt;The body section includes the data we are passing to the API. In this example, we're sending the user object defined in the first part of the above code block. But for the API to understand the data passed to it, we must first turn our user object into a string using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="noopener noreferrer"&gt;JSON.stringify() method&lt;/a&gt;. We must convert the object to a JSON string because Fetch() does not recognize JavaScript objects as a valid body response. This is a quirk of the Fetch API that developers must know when using Fetch()&lt;/p&gt;

&lt;p&gt;After the body is defined, we then go into the chain of promises. Starting with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code waits for a response. And when it receives a response as JSON, it uses the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Body/json" rel="noopener noreferrer"&gt;json() method&lt;/a&gt; to parse the response back to the JavaScript object format.&lt;/p&gt;

&lt;p&gt;The second link in our promise chain looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code takes the JavaScript object return in the previous promise link and logs this value to the console. This should send you the data you sent, and it may include an id and time stamp that was generated by the API as the data was posted to the database.&lt;br&gt;
The final link in the promise chain alerts us of any errors in the process by logging errors to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This break down of the Fetch API has covered some of the basics. As you grow as a developer, you'll find use cases for more of its functionality. As always, the Mozilla Development Network is the best starting place to read the documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  AXIOS
&lt;/h2&gt;

&lt;p&gt;Axios is a popular library used to make HTTP requests to RESTful APIs. The library replaces the functionality of the Fetch API, and adds some improvements. For instance, the Axios library will handle some of the data type conversions for you, so you're not always using JSON.stringify or relying on the text() method.&lt;/p&gt;

&lt;p&gt;Consider the similarities and differences of the Axios HTTP requests below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Send a POST request&lt;/span&gt;

&lt;span class="nf"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user/12345&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Falcon&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Send a GET request&lt;/span&gt;

&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;USER_ID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;XYZ543&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, you'll see that Axios differs from Fetch in that we don't have to change the format of the response. This reduces some complexity for us as developers, and makes the code easier to read.&lt;/p&gt;

&lt;p&gt;Axios can be installed via your &lt;a href="https://en.wikipedia.org/wiki/Package_manager" rel="noopener noreferrer"&gt;package manager&lt;/a&gt; of choice or accessed through a CDN, which is when you gain access to Axios by linking your HTML document with a script tag provided by Axios.&lt;/p&gt;

&lt;p&gt;To learn more about Axios, visit their GitHub page at: &lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;https://github.com/axios/axios&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>The API Series - Part 1: An Intro to APIs</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Thu, 22 Apr 2021 14:14:54 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-api-series-part-1-an-intro-to-apis-1bd</link>
      <guid>https://dev.to/vetswhocode/the-api-series-part-1-an-intro-to-apis-1bd</guid>
      <description>&lt;p&gt;APIs are the workhorse of modern web development. They put the "A" in JAMstack. And knowing how to work with them is a requirement for a career in frontend web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is An API
&lt;/h2&gt;

&lt;p&gt;API stands for Application Programming Interface. An API's function is to relay information, requests, and responses between two or more programs or machines.&lt;/p&gt;

&lt;p&gt;An example of an API you might need to use one day is Stripe. Stripe is a software company that creates software that processes online payments. They have developed the Stripe API, which allows any developer on the planet to interact with Stripe's payment processing software.&lt;/p&gt;

&lt;p&gt;By using the &lt;a href="https://stripe.com/docs/api"&gt;Stripe API&lt;/a&gt;, you can add payment processing functionality to a website without possessing that specific area of software and banking expertise.&lt;/p&gt;

&lt;p&gt;Sometimes an API simply provides access to a third-party database. An example of this would be the &lt;a href="https://www.programmableweb.com/api/open-eangtin-database-rest-api"&gt;Open EAN/GTIN Database API&lt;/a&gt;, which allows you to access product information based on barcode details.&lt;/p&gt;

&lt;p&gt;Some APIs allow you to add to a database. An example of this is the &lt;a href="https://developer.twitter.com/en/docs/twitter-api"&gt;Twitter API&lt;/a&gt;, which allows you to add Twitter posts to your feed via the API.&lt;/p&gt;

&lt;p&gt;The core similarity is that an API allows you to interact with software that you did not write and machines and data that you do not own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of APIs
&lt;/h2&gt;

&lt;p&gt;In this tutorial we are focusing on web service APIs. These are APIs that are designed to pass information between machines over networks like the internet, but there can also be local APIs.  can be structured differently, which affects how you interact with, or consume, the API. So it's important to know about the common types. &lt;/p&gt;

&lt;h3&gt;
  
  
  REST
&lt;/h3&gt;

&lt;p&gt;By far the most common since 2000, the REST, or RESTful, API is one that conforms to the constraints of the REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer. By working within a set of architectural constraints, the RESTful APIs provide consistency to all developers. The reason RESTful APIs are so common is that they offer a standardized methodology for making requests to an API. So once a developer works with one REST API, other REST APIs are going to function in a similar way. If you want a career in frontend web development, learn to master consuming RESTful APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  GraphQL
&lt;/h3&gt;

&lt;p&gt;An emerging API type, GraphQL API data is presented as a schema, which can be viewed by developers within the GraphiQL development environment. Frontend developers use the GraphQL query language to consume the data, providing the frontend, or client, with only the necessary data. Since this is an emerging technology, it is important to learn to consume GraphQL APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  SOAP
&lt;/h3&gt;

&lt;p&gt;SOAP APIs are an older format, and you might encounter them when working on a legacy project. This tutorial will not cover SOAP APIs, though there are plenty of resources available online should you run into a SOAP API in your career.&lt;/p&gt;

&lt;h3&gt;
  
  
  XML-RPC / JSON RPC
&lt;/h3&gt;

&lt;p&gt;These API types are older. Both follow a strict format that developers can rely on. One uses XML, and the other uses JSON data.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Access
&lt;/h2&gt;

&lt;p&gt;Some APIs are public. Some APIs require a developer key, which functions as an authorization protocol allowing access. These keys are acquired when registering with the API provider. &lt;br&gt;
For example, Stripe requires a developer key so they know who is transferring money! Also, since some APIs charge for use, this is a way of tracking usage.&lt;/p&gt;

&lt;p&gt;As a rule, it's highly recommended to keep your keys private. If someone else uses your key, you could get charged for their activity! Here is a good article on keeping your API keys secure: &lt;a href="https://www.freecodecamp.org/news/how-to-securely-store-api-keys-4ff3ea19ebda/"&gt;Best Practices For Securely Storing API Keys&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow for future posts on how to consume RESTful and GraphQL APIs.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Classless CSS Isn't Trashy</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Tue, 02 Feb 2021 16:22:58 +0000</pubDate>
      <link>https://dev.to/vetswhocode/classless-css-isn-t-trashy-3c43</link>
      <guid>https://dev.to/vetswhocode/classless-css-isn-t-trashy-3c43</guid>
      <description>&lt;p&gt;Can you write a nice-looking website without adding classes or IDs to your HTML? That's exactly what classless CSS promises, though in practice you'll find you'll likely need to add some customization to get it just the way you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Classless CSS
&lt;/h2&gt;

&lt;p&gt;Classless CSS is a design philosophy that adds properties and property values to type selectors only. A &lt;a href="https://dev.to/vetswhocode/the-css-series-part-10-specificity-4ge9"&gt;type selector&lt;/a&gt; is an HTML tag, so something like h1, p, form, div, etc.&lt;/p&gt;

&lt;p&gt;Since every HTML element has a predefined style, a plain HTML doc will look good once the classless CSS stylesheet is linked.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get Started
&lt;/h2&gt;

&lt;p&gt;There are several classless CSS stylesheets available for use, and these are often times linked to your HTML document via a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/CDN"&gt;Content Delivery Network&lt;/a&gt;. Basically, there's a stylesheet stored on a server that you can link your HTML to. Below are a few options, and their websites are demos for what the stylesheet will do to plain HTML:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://watercss.netlify.app/"&gt;Water.css&lt;/a&gt;&lt;br&gt;
&lt;a href="https://newcss.net/"&gt;New CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://igoradamenko.github.io/awsm.css/elements.html"&gt;AWSM CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://css-pkg.github.io/style.css/"&gt;Style CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://writ.cmcenroe.me/"&gt;Writ CSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many others out there, which can be found by searching for classless CSS stylesheets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Your Own Style
&lt;/h2&gt;

&lt;p&gt;Another option is to build your own classless stylesheet for reuse in your future projects. We all have our own style, and it's often easier and more satisfying to work with something you've crafted.&lt;/p&gt;

&lt;p&gt;One way to go about this, is that you can download an existing classless stylesheet and tweak it to your liking.&lt;/p&gt;

&lt;p&gt;Scott Tolinski of Syntax.fm podcast fame also teaches a course on building your own classless CSS stylesheet from scratch. His &lt;a href="https://www.leveluptutorials.com/?ref=nbhankes"&gt;Level Up Tutorials&lt;/a&gt; course, Modern CSS Design Systems, covers this topic in much more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Have you ever made a project using classless CSS? If so, leave a comment so other readers can hear about your experience!
&lt;/h3&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Upgrade Your CSS: The Syntax.fm Typography Sizing Strategy</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Tue, 26 Jan 2021 14:20:19 +0000</pubDate>
      <link>https://dev.to/nbhankes/upgrade-your-css-the-syntax-fm-typography-sizing-strategy-3hmf</link>
      <guid>https://dev.to/nbhankes/upgrade-your-css-the-syntax-fm-typography-sizing-strategy-3hmf</guid>
      <description>&lt;p&gt;In a &lt;a href="https://syntax.fm/show/319/hasty-treat-css-typography-and-systems"&gt;recent episode&lt;/a&gt; of the Syntax.fm podcast, Wes Bos and Scott Tolinski discuss how they handle typography sizing in their applications. I decided to try it out in Codepen and share my results here.&lt;/p&gt;

&lt;h3&gt;
  
  
  In short, here's the approach:
&lt;/h3&gt;

&lt;p&gt;1.) A range of font sizes are declared as &lt;a href="https://dev.to/vetswhocode/the-css-series-part-11-custom-properties-nkg"&gt;custom properties&lt;/a&gt;&lt;br&gt;
2.) Sizing is declared as &lt;a href="https://dev.to/vetswhocode/the-css-series-part-6-css-units-a02"&gt;rem units&lt;/a&gt;&lt;br&gt;
3.) The root font size is changed via &lt;a href="https://dev.to/vetswhocode/the-css-series-part-12-mobile-first-and-responsive-design-598l"&gt;@media queries&lt;/a&gt; to shrink and grow the rem sizes as needed&lt;/p&gt;
&lt;h3&gt;
  
  
  This approach solves several problems:
&lt;/h3&gt;

&lt;p&gt;1.) Standardizes sizing&lt;br&gt;
2.) Simplifies your CSS&lt;br&gt;
3.) Responsive to changes in browser size&lt;/p&gt;
&lt;h2&gt;
  
  
  How To Start
&lt;/h2&gt;

&lt;p&gt;First, set up your custom properties with a range of font sizes in rem units&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--text-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3rem&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;You can name your custom properties however you like, but I found using a number at the end helped me keep it straight in my head. Some might prefer their names to be --smallest-font, --extra-large-font, etc. Whatever works for you is best.&lt;/p&gt;

&lt;p&gt;You can also use whatever rem values you like. I found the 0.5rem to 3rem range useful for this short example. Out in the wild, there might be uses for more text size options and a larger range.&lt;/p&gt;

&lt;p&gt;I then went through some common elements and assigned them these custom variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-1&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;You'll notice I used the font sizing custom properties to set margin sizing. I don't see the downside, but in the future, perhaps I'll define a margin sizing custom property, as well.&lt;/p&gt;

&lt;p&gt;Scott Tolinski's &lt;a href="https://www.leveluptutorials.com/?ref=nbhankes"&gt;Level Up Tutorials&lt;/a&gt; course, Modern CSS Design Systems, covers this topic in much more detail, if you're looking to Level Up your CSS.&lt;/p&gt;

&lt;p&gt;Take a look at the Codepen example to see this strategy implemented. I use JavaScript to cycle the root font size between 16px and 20px, so you can easily visualize how a change to the root font size proportionally changes any sizes declared as rem units.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nbhankes/embed/KKgLmwr?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is standardization important?
&lt;/h2&gt;

&lt;p&gt;When you define your unit sizes in custom properties, you can change the font sizes throughout the entire document by changing a single value in the custom properties, versus combing through the entire stylesheet to adjust the font sizes for individual classes and html type selectors. &lt;/p&gt;

&lt;h2&gt;
  
  
  How does this simplify design?
&lt;/h2&gt;

&lt;p&gt;Coming up with a strategy like this simplifies design. Sizing decisions are pre-made for you (and by you), so your task is to find the best fit from your limited options. When compared to selecting the perfect size from infinite options, you'll find that this approach is faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is this responsive?
&lt;/h2&gt;

&lt;p&gt;rem units are sized relative to the root font size, meaning 1 rem is equal to the font size set in the :root or html &lt;a href="https://dev.to/vetswhocode/the-css-series-part-3-selectors-49b8"&gt;property&lt;/a&gt;. So if the root font size is decreased via a &lt;a href="https://dev.to/vetswhocode/the-css-series-part-12-mobile-first-and-responsive-design-598l"&gt;@media query&lt;/a&gt; as the screen size gets smaller, then all values with property values declared in rem units will resize proportionally.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>The CSS Series: Part 13 - CSS Frameworks, CSS-in-JS, Architecture, and Accessibility</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Tue, 19 Jan 2021 15:46:08 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-css-series-part-13-css-frameworks-css-in-js-architecture-and-accessibility-9kc</link>
      <guid>https://dev.to/vetswhocode/the-css-series-part-13-css-frameworks-css-in-js-architecture-and-accessibility-9kc</guid>
      <description>&lt;p&gt;While this series hasn't covered every detail of CSS, I hope it leaves you with a solid foundation in CSS. But before you depart, there are some CSS topics beyond the fundamentals that you will want to be aware of. This page is simply a list of such topics with brief descriptions. If something interests you, you'll now have the resources to get started on your path of self-directed learning.&lt;/p&gt;

&lt;p&gt;You can catch up on the rest of the series at the links below:&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-1-an-intro-to-css-2368"&gt;Part 1: An Intro to CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-2-how-to-link-a-stylesheet-to-your-index-html-file-1d0e"&gt;Part 2: How to Link a Stylesheet to Your index.html File&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-3-selectors-49b8"&gt;Part 3: Selectors&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-4-properties-17d7"&gt;Part 4: Properties&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-5-the-box-model-32i"&gt;Part 5: The Box Model&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-6-css-units-a02"&gt;Part 6: CSS Units&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-7-css-units-362i"&gt;Part 7: Flexbox&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-8-css-grid-109m"&gt;Part 8: CSS Grid&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-9-display-property-h1h"&gt;Part 9: Display Property&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-10-specificity-4ge9"&gt;Part 10: Specificity&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-11-custom-properties-nkg"&gt;Part 11: Custom Properties&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-12-mobile-first-and-responsive-design-598l"&gt;Part 12: Mobile and Responsive Design&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;A basic understanding of CSS&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Documentation and Resources
&lt;/h2&gt;

&lt;p&gt;There are several websites that strive to document everything about CSS. Others show how to harness the fundamentals to create exciting functionality. Below is a list of some of these resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mozilla Development Network&lt;/strong&gt;: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Dev Docs&lt;/strong&gt;: &lt;a href="https://devdocs.io/css/"&gt;https://devdocs.io/css/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;CSS Tricks&lt;/strong&gt;: &lt;a href="https://css-tricks.com/"&gt;https://css-tricks.com/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Frameworks
&lt;/h2&gt;

&lt;p&gt;There are several popular CSS frameworks you can use that supply completed CSS stylesheets to you. These styles render when you add the framework's pre-defined class names into your HTML. Some popular frameworks include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bootstrap&lt;/strong&gt;: &lt;a href="https://getbootstrap.com/"&gt;https://getbootstrap.com/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Tailwind CSS&lt;/strong&gt;: &lt;a href="https://tailwindcss.com/"&gt;https://tailwindcss.com/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Bulma&lt;/strong&gt;: &lt;a href="https://bulma.io/"&gt;https://bulma.io/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS-in-JS
&lt;/h2&gt;

&lt;p&gt;There are libraries and tooling that allow developers to define all their CSS designs directly from within JavaScript. This is especially useful when developing within JS-centric frameworks and libraries like React. &lt;/p&gt;

&lt;p&gt;If you're just learning CSS, these won't make much sense now. But as you progress into developing with something like React, you may encounter some issues that can best be solved using some of the links below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic CSS-in-JS&lt;/strong&gt;: &lt;a href="https://sebastienlorber.com/atomic-css-in-js%E2%80%A6"&gt;https://sebastienlorber.com/atomic-css-in-js…&lt;/a&gt; &lt;br&gt;
&lt;strong&gt;Tailwind-in-JS&lt;/strong&gt;: &lt;a href="https://github.com/ben-rogerson/twin.macro%E2%80%A6"&gt;https://github.com/ben-rogerson/twin.macro…&lt;/a&gt; &lt;br&gt;
&lt;strong&gt;styled-components&lt;/strong&gt;: &lt;a href="https://styled-components.com"&gt;https://styled-components.com&lt;/a&gt; &lt;br&gt;
&lt;strong&gt;theme-ui&lt;/strong&gt;: &lt;a href="https://theme-ui.com"&gt;https://theme-ui.com&lt;/a&gt; &lt;br&gt;
&lt;strong&gt;styled-system&lt;/strong&gt;: &lt;a href="https://styled-system.com"&gt;https://styled-system.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Architecture
&lt;/h2&gt;

&lt;p&gt;Often times large code bases can become so large and compartmentalized, that it's hard to locate your design elements and your styling. Making changes suddenly requires more time navigating around folders than actually writing code. Due to this common problem, developers have shared some of their strategies on how to think about your CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SMACSS&lt;/strong&gt;: &lt;a href="http://smacss.com/"&gt;http://smacss.com/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Atomic CSS&lt;/strong&gt;: &lt;a href="https://acss.io/"&gt;https://acss.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's no right way to write CSS. So if you discover something that works for you, consider sharing it with the developer community  a blog post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Accessibility
&lt;/h2&gt;

&lt;p&gt;Web designers have a responsibility to make their websites accessible to visitors with disabilities. For example, people with poor eyesight will be able to read better if there is a lot of contrast between the background color and the font color. These are things most of us wouldn't consider naturally, so it's important to read up on accessibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A11y&lt;/strong&gt;: &lt;a href="https://www.a11yproject.com/"&gt;https://www.a11yproject.com/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;7 Things Designers Need To Know&lt;/strong&gt;: &lt;a href="https://medium.com/salesforce-ux/7-things-every-designer-needs-to-know-about-accessibility-64f105f0881b"&gt;https://medium.com/salesforce-ux/7-things-every-designer-needs-to-know-about-accessibility-64f105f0881b&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Learning web design is a journey that never ends. There's always more to learn and it's not humanly possible to learn it all. Persistence will take you far. Curiosity will make the process enjoyable.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>The CSS Series: Part 12 - Mobile First and Responsive Design</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Tue, 12 Jan 2021 17:19:30 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-css-series-part-12-mobile-first-and-responsive-design-598l</link>
      <guid>https://dev.to/vetswhocode/the-css-series-part-12-mobile-first-and-responsive-design-598l</guid>
      <description>&lt;p&gt;Because your web designs will be viewed on screens ranging from an old iPhone to a 27" iMac and beyond, you'll often encounter design situations where the website will require two or more designs in order to look nice and remain functional across multiple screen widths. Responsive design is web design that renders well at any browser size.&lt;/p&gt;

&lt;p&gt;When developing a website or app from the ground up, you'll find that beginning by designing for mobile has many advantages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Mobile First Philosophy
&lt;/h2&gt;

&lt;p&gt;Mobile first design simply means that developers begin their project by designing for mobile. This isn't simply an opinion, but there's logic behind it. Here are some key reasons this approach makes sense:&lt;/p&gt;

&lt;p&gt;1) Mobile applications have bandwidth constraints, meaning that only core functionality should be included in mobile design.&lt;br&gt;
It's most often easier to add to a design than to take away. So starting with a no frills, basic functionality design forces you to streamline and avoid the type of complexity that makes life harder for developers and users, alike.&lt;/p&gt;

&lt;p&gt;Due to bandwidth constraints, you'll want to avoid animations, excessive pictures, and gradients, giving you more time to focus on things like functionality, user experience, and accessibility.&lt;br&gt;
The focus on core functionality increases your chances of not bogging down on functionality and designs that aren't necessary to launch your project. This makes you more likely to finally complete side project!&lt;/p&gt;

&lt;p&gt;2) HTML tags most often default to a display property value of block.&lt;/p&gt;

&lt;p&gt;A mobile phone design is essentially a narrow column with HTML design elements stacked on top of each other. The default block property value automatically stacks HTML elements on top of one another, meaning that, by default, the HTML will be (mostly) optimized for mobile viewing. It's when screens become wider that developers begin placing items side by side in order to fill the space. Let's look at an example from Airbnb:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RKQGMmfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/rmrsqecgeh9v3yl69md7.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RKQGMmfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/rmrsqecgeh9v3yl69md7.JPG" alt="airbnb mobile design example" width="640" height="1136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we look at the layout of the above mobile Airbnb page, almost all containers are stacked on top of one another. This is often the default behavior for HTML elements, so before you even apply CSS to your html, the layout is close to your mobile design needs.&lt;/p&gt;

&lt;p&gt;Oppose this to the desktop layout below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mdcqb7KZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zcgskb65g8l89x2jxhwn.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mdcqb7KZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zcgskb65g8l89x2jxhwn.JPG" alt="Alt Text" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's the exact same content, but now we see the design splitting into two major columns. This is not the default behavior for html and requires additional CSS to achieve.&lt;/p&gt;

&lt;p&gt;3) Google search algorithms place added value on websites optimized for mobile viewing.&lt;br&gt;
By starting with mobile design first, you ensure you'll have better odds of being found by the world's most popular search engine.&lt;/p&gt;

&lt;p&gt;4) Mobile browsing is becoming the new normal.&lt;/p&gt;

&lt;p&gt;5) When you finish your mobile design, your site will work on a desktop. &lt;/p&gt;

&lt;p&gt;It may not look pretty, but it will be functional.&lt;/p&gt;
&lt;h2&gt;
  
  
  Responsive Design
&lt;/h2&gt;

&lt;p&gt;Responsive design is design that optimizes for whatever browser width it displays in. The flexbox display property is valuable for this as are the following CSS functions.&lt;/p&gt;
&lt;h3&gt;
  
  
  @media Queries
&lt;/h3&gt;

&lt;p&gt;As a developer, you have several tools to help you display the website differently depending on the browser width. @media queries are, as of 2020, the best CSS solution to this problem:&lt;/p&gt;

&lt;p&gt;"The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used."&lt;/p&gt;

&lt;p&gt;In terms of mobile development, you can have different sections of code apply to different browser widths by setting up @media queries. Let's look at an example to so you understand the concept:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&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;In the example above, when the browser is less than 500 pixels in width, the @media rule takes over and the body background color will render as blue. When the browser width is greater than 55 pixels, the body background renders as white.&lt;/p&gt;

&lt;h3&gt;
  
  
  clamp()
&lt;/h3&gt;

&lt;p&gt;A newer approach that's gaining popularity is the clamp() CSS function. The clamp() function takes in three values that allow developers to set a minimum, preferred, and maximum value to any property. The order is as follows clamp(minimum value, preferred value, maximum value).&lt;/p&gt;

&lt;p&gt;Let's takes a look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;font-size&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="nt"&gt;vw&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the font size render at a maximum of 2 rems and a minimum of 2.5vw. This approach allows to you create responsive sizing that doesn't get too large or small at the far edges of any range. This is the type of CSS function you'll want to play around with to understand more. &lt;/p&gt;

&lt;p&gt;Here's a demo from the MDN documentation worth looking at: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/clamp()"&gt;clamp() demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can catch up on the rest of the series at the links below:&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-1-an-intro-to-css-2368"&gt;Part 1: An Intro to CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-2-how-to-link-a-stylesheet-to-your-index-html-file-1d0e"&gt;Part 2: How to Link a Stylesheet to Your index.html File&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-3-selectors-49b8"&gt;Part 3: Selectors&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-4-properties-17d7"&gt;Part 4: Properties&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-5-the-box-model-32i"&gt;Part 5: The Box Model&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-6-css-units-a02"&gt;Part 6: CSS Units&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-7-css-units-362i"&gt;Part 7: Flexbox&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-8-css-grid-109m"&gt;Part 8: CSS Grid&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-9-display-property-h1h"&gt;Part 9: Display Property&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-10-specificity-4ge9"&gt;Part 10: Specificity&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-11-custom-properties-nkg"&gt;Part 11: Custom Properties&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The CSS Series: Part 11 - Custom Properties</title>
      <dc:creator>Nathan B Hankes</dc:creator>
      <pubDate>Tue, 05 Jan 2021 15:58:01 +0000</pubDate>
      <link>https://dev.to/vetswhocode/the-css-series-part-11-custom-properties-nkg</link>
      <guid>https://dev.to/vetswhocode/the-css-series-part-11-custom-properties-nkg</guid>
      <description>&lt;p&gt;Once you pick a color palette for your website, you can imagine how often you'll write those color values in your stylesheet. You could have the same color listed as a property value in thirty or more places! Now imagine if your client or team suddenly needs to change your site's color palette? You'd have to go through the entire document and change each of those 30+ values!&lt;/p&gt;

&lt;p&gt;One way to avoid this is to use CSS custom properties, also known as CSS variables. CSS custom properties are variables defined by CSS authors that contain specific values to be reused throughout a document. This tutorial will show you how to create and use CSS variable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding CSS Custom Properties
&lt;/h2&gt;

&lt;p&gt;Let's say our client thinks they'd like their website background to be gray. And all borders are black. Font colors should be white, they say. But you've worked with enough people to know that this will change a few times before finishing your project, so you decide to set up custom properties. You would create custom properties for each of these colors like so:&lt;/p&gt;

&lt;p&gt;/ stylesheet.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&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;By declaring the CSS custom properties inside of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:root"&gt;root pseudo-class&lt;/a&gt;, these custom properties are globally available throughout your entire project. Assigning a custom value to a div declaration means that the custom variable would only be available to div types. This is due to a process referred to as scoping, which you'll learn more about as you dive into a language like JavaScript. But for now, let's carry on with our website design stylesheet, inserting these custom properties into your project like so:&lt;/p&gt;

&lt;p&gt;/ stylesheet.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nc"&gt;.header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--border&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--font&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;h4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--font&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--font&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your html is styled with the property values assigned to your custom properties of --background, --border, and --font. As you can see, if you needed to change the color palette of the entire website, all you would need to do is change the property value assigned to your custom property declarations inside of the root pseudo-class.&lt;/p&gt;

&lt;p&gt;The benefits of CSS custom properties are not limited to colors and you're really only limited by your imagination.&lt;/p&gt;

&lt;p&gt;You can catch up on the rest of the series at the links below:&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-1-an-intro-to-css-2368"&gt;Part 1: An Intro to CSS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-2-how-to-link-a-stylesheet-to-your-index-html-file-1d0e"&gt;Part 2: How to Link a Stylesheet to Your index.html File&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-3-selectors-49b8"&gt;Part 3: Selectors&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-4-properties-17d7"&gt;Part 4: Properties&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-5-the-box-model-32i"&gt;Part 5: The Box Model&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-6-css-units-a02"&gt;Part 6: CSS Units&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-7-css-units-362i"&gt;Part 7: Flexbox&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-8-css-grid-109m"&gt;Part 8: CSS Grid&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-9-display-property-h1h"&gt;Part 9: Display Property&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/vetswhocode/the-css-series-part-10-specificity-4ge9"&gt;Part 10: Specificity&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>100daysofcode</category>
      <category>design</category>
    </item>
  </channel>
</rss>
