<?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: Azamah Jr</title>
    <description>The latest articles on DEV Community by Azamah Jr (@kaid00).</description>
    <link>https://dev.to/kaid00</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%2F646755%2Fc8ea4e3b-e513-4d16-b728-0553b9575f21.jpeg</url>
      <title>DEV Community: Azamah Jr</title>
      <link>https://dev.to/kaid00</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kaid00"/>
    <language>en</language>
    <item>
      <title>Appwrite storage service</title>
      <dc:creator>Azamah Jr</dc:creator>
      <pubDate>Thu, 28 Oct 2021 19:55:04 +0000</pubDate>
      <link>https://dev.to/kaid00/appwrite-storage-service-39pc</link>
      <guid>https://dev.to/kaid00/appwrite-storage-service-39pc</guid>
      <description>&lt;p&gt;Appwrite is an open-source, self-hosted Backend-as-a-Service which provides a suite of SDKs and APIs to facilitate development on any platform. In this article we are going to look at Appwrites' Storage service and API which lets you manage your project files&lt;/p&gt;

&lt;p&gt;Appwrites storage service grants read and write permissions to manage access to every file in storage, this lets authenticated users upload, download, view and query and manage all project files. &lt;/p&gt;

&lt;p&gt;Storage can be managed and manipulated in two ways;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using Appwrites console&lt;/li&gt;
&lt;li&gt;Using Appwrites storage API, which provides various endpoints to manipulate files in storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To demonstrate Appwrites storage service, in this article we will be utilizing Appwrites storage API to manage and manipulate images files in our demo react app&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;This article assumes you have appwrite installed, if you don't heres an &lt;a href="https://appwrite.io/docs/installation"&gt;article&lt;/a&gt; to get you started&lt;/li&gt;
&lt;li&gt;Basic knowledge of javascript and react&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  About the demo app
&lt;/h2&gt;

&lt;p&gt;The front end of the app has been pre built, and in this article we would focus only on implementing functionality in the app using Appwrite as our backend and Appwrites storage API. The following functionalities;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload an image to storage&lt;/li&gt;
&lt;li&gt;Delete an image &lt;/li&gt;
&lt;li&gt;Get and Display all images we currently have stored&lt;/li&gt;
&lt;li&gt;Download stored images &lt;/li&gt;
&lt;li&gt;For this demo we want to provide authentication so users can have permissions to read and write to storage , but we want to keep it simple here so we are going to implement an Anonymous login using Appwrites createAnonymousSession() method , where users can create an account without providing information such as an email address, username or password.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementing each of the above functionalities we will be utilizing endpoints from the storage API, and as such we will gain hands on experience in utlizing the storage API in a real word scenarios.&lt;/p&gt;

&lt;p&gt;Note: We will not cover how to build the demo app with react in this video. However i'll provide links to the projects starter files, which you can clone from github and follow along to implement functionality with Appwrite&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Clone the project starter files &lt;a href="https://github.com/Kaid00/purp-flower.git"&gt;Here&lt;/a&gt; to code along&lt;/p&gt;

&lt;p&gt;Once you've cloned the project repository, navigate to the project folder and run the following command in the projects root to install the projects dependencies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create new Appwrite project
&lt;/h3&gt;

&lt;p&gt;In Appwrites console, create a new project and name it &lt;code&gt;purp-flower&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In the project we just created, click the add platform button and add a web platform so we can initialize the web SDK and interact with Appwrite services in our react app&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring Appwrite
&lt;/h3&gt;

&lt;p&gt;In the project root, run the following command to add Appwrite to the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;appwrite &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First up, lets import the Appwrite module, navigate to &lt;code&gt;src/appwrite/appwrite.congfig.js&lt;/code&gt; and enter the following code&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;// Import the Appwrite module&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Appwrite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;appwrite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to initialize our web SDK with our project ID and our Appwrite endpoint, which can both be found in the project settings page in the Appwrite 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="c1"&gt;// Init your Web SDK&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appwrite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Appwrite&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;appwrite&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setEndpoint&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://localhost/v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Your Appwrite Endpoint&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setProject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;455x34dfkj&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Your project ID&lt;/span&gt;
&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Ok lets begin implementing our apps functionality &lt;/p&gt;

&lt;h3&gt;
  
  
  Uploading images &amp;amp; Anonymous login
&lt;/h3&gt;

&lt;p&gt;Before a user can be permitted to upload an image to storage, they have to be authenticated, as earlier mentioned we will implement anonymous login to authenticate users without requiring usernames and passwords&lt;/p&gt;

&lt;p&gt;Uploading a file to storage using the web SDK requires the &lt;a href="https://appwrite.io/docs/client/storage#storageCreateFile"&gt;storage.createFile() &lt;/a&gt;method. This method requires three parameters: a file, an array of strings to define the read permissions, and an array of strings to define write permissions.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;src/app.js&lt;/code&gt; file in the project, lets create an &lt;code&gt;uploadImage()&lt;/code&gt; function, copy 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;// 1. Upload images to appwrite&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uploadImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Checks if user is logged in current session&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSession&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;current&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;// Upload image&lt;/span&gt;
          &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;*&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;*&lt;/span&gt;&lt;span class="dl"&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="nx"&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;Image uploaded successfully!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Reloads window on upload&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;// Create anonymous user&lt;/span&gt;
          &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createAnonymousSession&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;*&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;*&lt;/span&gt;&lt;span class="dl"&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="nx"&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;New user was created &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reload&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="k"&gt;catch&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;Lets take a closer look at the &lt;code&gt;storage.createFile()&lt;/code&gt;method&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;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;*&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;*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first parameter of this method is an image within an array of images, the second parameter defines the read parameters, setting the array of strings to and asterisks, grants read access to all users no matter their role. We can restrict this access to users of certain roles. The third parameter defines the write permissions, and like the read permission, all users of the application have been granted write access &lt;/p&gt;

&lt;p&gt;Next we get the currently logged in user, if there exist a logged in user, we upload the image file to storage and if the user isn't authenticated and logged in, we call the &lt;code&gt;account.createAnonymousSession&lt;/code&gt; which creates and logs in an anonymous user. Once thats done, we then upload the image.&lt;/p&gt;

&lt;p&gt;Now go ahead and upload a couple of images to storage using the demo app&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cdwGGSA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/726i07jzz7ier44bnequ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cdwGGSA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/726i07jzz7ier44bnequ.png" alt="Appwrite storage API demo app by Azamah Jr" width="880" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can check to see if our images were uploaded to storage using Appwrites console, and as you can see below the images were uploaded &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b0ppW56m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jwhgqkxsq1etczjrckl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b0ppW56m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jwhgqkxsq1etczjrckl.png" alt="Appwrite storage console " width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Getting a list of all images in storage
&lt;/h3&gt;

&lt;p&gt;To get a list of all images we have in storage we require the use of the &lt;a href="https://appwrite.io/docs/client/storage#storageListFiles"&gt;&lt;code&gt;storage.listFiles()&lt;/code&gt;&lt;/a&gt; method, once we get the list we will store it in an imageList state. Copy the code below to implement the &lt;code&gt;getAllStoredImg()&lt;/code&gt;function&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getAllStoredImg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;images&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listFiles&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;setImageList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&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;We would want our application to get the list of all images in storage each time the app reloads, the code below implements that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&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;getAllStoredImg&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;Now we have a list of all images currently in storage, next lets display the images, we  need to use the &lt;code&gt;storage.getFilePreview(imgID)&lt;/code&gt; method, and would take an image ID as parameter. &lt;/p&gt;

&lt;p&gt;As we probably have a lot of images stored, we therefore loop through the imageList state to get each image ID from the list and parse that as a parameter to the &lt;code&gt;storage.getFilePreview()&lt;/code&gt;method to preview the image, how this was done with react is beyond the scope of this article &lt;/p&gt;

&lt;p&gt;At this point the demo app should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sSkHsKqI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lrocm8457b2yniga8xki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sSkHsKqI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lrocm8457b2yniga8xki.png" alt="Appwrite storage API demo app - Azamah jr" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we are getting and displaying all the images we had stored. Next lets implement the delete and download features&lt;/p&gt;

&lt;h3&gt;
  
  
  Delete an image
&lt;/h3&gt;

&lt;p&gt;Deleting an image requires the use of &lt;a href="https://appwrite.io/docs/client/storage#storageDeleteFile"&gt;&lt;code&gt;storage.deleteFile()&lt;/code&gt;&lt;/a&gt;method, as a parameter we pass in the image Id of the image in storage which we want deleted&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;// 2. Delete an image&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deleteImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;imgId&lt;/span&gt;&lt;span class="p"&gt;)&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deleteFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;imgId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reload&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Image Deleted Successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;h3&gt;
  
  
  Download an image
&lt;/h3&gt;

&lt;p&gt;To download an image from storage we require the use of &lt;a href="https://appwrite.io/docs/client/storage#storageGetFileDownload"&gt;&lt;code&gt;storage.getFileDownload(imgID)&lt;/code&gt;&lt;/a&gt;method, this method takes the image ID as a parameter&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;downloadImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;imgId&lt;/span&gt;&lt;span class="p"&gt;)&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;downloadLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getFileDownload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;imgId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;downloadLink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&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;error&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;h3&gt;
  
  
  Conclusions
&lt;/h3&gt;

&lt;p&gt;We've implemented all the functionalities of our demo app, i am glad you made it this far. if you have any questions let me know down in the comments&lt;/p&gt;

&lt;p&gt;Here are some links if you want to learn more on the Appwrite features which were implemented in this article; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://appwrite.io/docs/client/storage"&gt;Appwrites Storage Services&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://appwrite.io/docs/client/account"&gt;Appwrite Accounts API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading, thats all for now ✌️&lt;/p&gt;

</description>
    </item>
    <item>
      <title>RESTful APIs in 4 minutes</title>
      <dc:creator>Azamah Jr</dc:creator>
      <pubDate>Mon, 06 Sep 2021 22:37:44 +0000</pubDate>
      <link>https://dev.to/kaid00/restful-apis-in-4-minutes-28p2</link>
      <guid>https://dev.to/kaid00/restful-apis-in-4-minutes-28p2</guid>
      <description>&lt;h2&gt;
  
  
  APIs, What Are They🤔?
&lt;/h2&gt;

&lt;p&gt;API stands for Application programming interface, it is an intermediary between two or more applications or services that provide a set of rules and definitions that define how the applications or services can connect and communicate with each other, all while abstracting how each application, involved in the communication is implemented. &lt;/p&gt;

&lt;p&gt;This communication entails sharing data and business functionalities between applications via HTTP (Hypertext Transfer Protocol). &lt;/p&gt;

&lt;p&gt;Web applications use APIs to connect client-facing, frontends to the backends functionality and data. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use APIs🤔
&lt;/h2&gt;

&lt;p&gt;APIs make it easier for apps running in different environments or written in different languages to share information, this can simplify app development, reduce development time and cost.&lt;/p&gt;

&lt;p&gt;Ok, let's say an application you are developing requires an authentication and authorization feature. Rather than delegating time and resources in building and maintaining a login system, the functionality provided by APIs of services such as  &lt;a href="https://auth0.com" rel="noopener noreferrer"&gt;Auth0&lt;/a&gt;  can be leveraged to authenticate/authorize and login users into the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  So What Are RESTful APIs?🤔
&lt;/h2&gt;

&lt;p&gt;Well REST stands for Representational State Transfer Architectural Style. A RESTful API is an API that conforms to the 6 guiding constraints of REST, such APIs could also be referred to as simply REST APIs&lt;/p&gt;

&lt;p&gt;These 6 constraints of REST are;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client-server architecture&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;REST architecture is composed of clients, servers, and resources, and it handles requests through HTTP messages, but the clients and servers must be completely independent of each other. The only information the client knows is the URI (Uniform Resource Identifier) of the requested resource. The server provides this requested resource by sending it through an HTTP response. The server shouldn't be able to modify the client application other than providing a requested resource.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Statelessness&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Session Data is sent to the server from the client in such a way that each data packet can be understood in isolation. The server does not retain session state or data, instead, session states or data are held with the client&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cacheability&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clients can cache server responses, caching can eliminate the need for some client-server interactions which further improves performance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Layered system:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clients and servers may not necessarily be connected directly with each other. They may be mediated by additional layers such as security layers, load balancers, and intermediate servers. These layers could offer additional features like load balancing, shared caches, and security.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code on demand (optional)&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Servers can extend the functionality of a client by transferring executable code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Uniform Interface:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All API requests for the same resource should look the same. The REST API should ensure that the same piece of data belongs to only one URI. Resources shouldn’t be too large but should contain every piece of information that the client might need&lt;/p&gt;

&lt;p&gt;If an API  violates any of the guiding constraints, it can not be considered a RESTful API&lt;/p&gt;

&lt;h2&gt;
  
  
  How RESTful APIs work👩‍🏭
&lt;/h2&gt;

&lt;p&gt;Let's take an example. We want to build a simple application that connects to a server and provides the functionality of creating, reading, updating, and deleting resources (also known as CRUD) within the database&lt;/p&gt;

&lt;p&gt;A RESTful API is built and used to connect and provide communication between our client-facing front end to the back end server and database.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1630962476666%2FIcYxwQfeV.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1630962476666%2FIcYxwQfeV.png" alt="Artboard 833.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When users of our application make client requests on the front end to retrieve a resource from within the database, the RESTful API is called, it makes a GET request to retrieve the resource, &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To create a resource within the database the RESTful API makes a POST request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To update a resource the RESTful API makes a PATCH request &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To delete a resource from within the database, the RESTful API makes a DELETE request to the Server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The resource can be delivered to the client in a variety of formats including HTML, plain text, or Javascript object notation (JSON). &lt;/p&gt;

&lt;p&gt;All HTTP methods can be used in RESTful API calls, we've seen the GET, POST, PATCH, and DELETE methods above. To learn more or have a refresher on HTTP, HTTP methods, and status codes as well as the Request-Response cycle check out this  &lt;a href="https://dev.to/kaid00/http-simplified-5eak"&gt;article&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Understanding the concepts of HTTP is fundamental to building and working with RESTful APIs, if you haven't come across this before, I suggest you take some time to read this  &lt;a href="https://dev.to/kaid00/http-simplified-5eak"&gt;article&lt;/a&gt;  to grasp the foundational concepts. In a later article, we will be building a RESTful API using ExpressJs and MongoDB.&lt;/p&gt;

&lt;p&gt;I really hope that you enjoyed reading this article and learned something from it. If you have any questions let me know in the comments. I am passionate about sharing knowledge and helping others reach their goals, let's connect on  &lt;a href="https://twitter.com/azamahjr" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;. That's all for now✌️&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>node</category>
      <category>webdev</category>
    </item>
    <item>
      <title>HTTP Simplified</title>
      <dc:creator>Azamah Jr</dc:creator>
      <pubDate>Fri, 03 Sep 2021 03:19:34 +0000</pubDate>
      <link>https://dev.to/kaid00/http-simplified-5eak</link>
      <guid>https://dev.to/kaid00/http-simplified-5eak</guid>
      <description>&lt;p&gt;If you have an interest in Web development and building APIs, understanding the concepts of HTTP is vital.&lt;/p&gt;

&lt;p&gt;In this article you are going to learn the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What HTTP is, and its characteristics
&lt;/li&gt;
&lt;li&gt;A brief history of HTTP versions&lt;/li&gt;
&lt;li&gt;What Sessions are and their usage &lt;/li&gt;
&lt;li&gt;The Request-Response cycle&lt;/li&gt;
&lt;li&gt;HTTP Request and Response messages&lt;/li&gt;
&lt;li&gt;HTTP methods and their operations&lt;/li&gt;
&lt;li&gt;HTTP Status codes, their meanings, and what operations they perform&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🤔What is HTTP?
&lt;/h2&gt;

&lt;p&gt;HyperText Transfer Protocol (HTTP) is a stateless, connection-less, request-response protocol that consists of rules which define communications between clients and servers connected over an established &lt;a href="https://searchnetworking.techtarget.com/definition/TCP" rel="noopener noreferrer"&gt;Transmission Control Protocol (TCP)&lt;/a&gt; connection&lt;/p&gt;

&lt;p&gt;Once there is an established connection between the client and the server, HTTP defines rules for transferring data such as images, text, and other multimedia between the client and the server&lt;/p&gt;

&lt;p&gt;Before delving any further, let's define some basic terminologies which will be mentioned in the article.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clients: The client is a web browser, search engine, or robot. The client sends the request message to the server &lt;/li&gt;
&lt;li&gt;Servers: A web server that receives and responds to the request message sent by the clients, by sending a response message back to the client &lt;/li&gt;
&lt;li&gt;User: The individual who enters a URI into the browser or request for specific resource within an application&lt;/li&gt;
&lt;li&gt;URI( Uniform Resource Identifier): it is used to identify a given unique resource on the web&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📜 History of HTTP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTTP/1.0: It was the original HTTP. It opened a new TCP connection for each HTTP request-response exchange, this approach is less efficient when multiple requests are sent in succession, hence the need to address this flaw in later versions&lt;/li&gt;
&lt;li&gt;HTTP/1.1: To mitigate the flaws of HTTP/1.0, pipelining was implemented which allowed multiple HTTP request-response exchanges over a single TCP connection&lt;/li&gt;
&lt;li&gt;HTTP/2 goes a step further by multiplexing messages within frames over a single open TCP connection

&lt;ul&gt;
&lt;li&gt;HTTP/2 messages a not human-readable and are embedded into frames which allows optimizations like compressions of HTTP headers and multiplexing.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Characteristics of HTTP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTTP is stateless:  There's no link between any two or more HTTP requests messages being successively sent out on the same TCP connection, this means from the server's perspective each HTTP request message is considered isolated and unique&lt;/li&gt;
&lt;li&gt;HTTP is not connection-based: Before a client and server can exchange requests and responses there must be an established connection between the client and server, but HTTP is not connection-based, hence it relies on the TCP transport layer which is a connection-based protocol, to establish a secure connection between the client and the server&lt;/li&gt;
&lt;li&gt;Once the server receives the HTTP request messages sent by the client on an opened TCP connection, the server analyzes and sends an HTTP response message to the client, after which the TCP connection is closed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although HTTP itself is stateless, there's a need to share state between multiple HTTP requests. HTTP cookies make it possible for the use of stateful sessions. &lt;/p&gt;

&lt;p&gt;HTTP cookies are added to the header of each HTTP request allowing session creations on each HTTP request, doing this makes it possible to share state between multiple HTTP requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  🤔What are Sessions
&lt;/h3&gt;

&lt;p&gt;A session is temporal storage on the server, each session consists of the session data and the session ID which identifies a specific session. The session data is stored on the server while the session ID is stored in the client(web browser) using HTTP cookies. To identify a specific session, the session ID is sent back to the server using HTTP cookies&lt;/p&gt;

&lt;h4&gt;
  
  
  Characteristics of Sessions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Sessions are unique for each user. So if there are 4 users who make a request to the server, there will be 4 sessions created on the server. &lt;/li&gt;
&lt;li&gt;During the request processing of each user, the user's sessions are available to all web pages on the application &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Sessions usage examples
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Sessions can be used to protect certain pages and routes so that only specific users can access them, we can keep track of the users when they log in, by storing their user's IDs in a session &lt;/li&gt;
&lt;li&gt;Sessions can be used to keep track of a users' log status. So we can restrict access to protected resources and routes, to being available to logged-in users only. When a user logs in, their JSON Web Token(JWT) is stored in a session, and with subsequent user requests to a resource, it can be checked to see if the user is logged in&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🔂The HTTP process
&lt;/h2&gt;

&lt;p&gt;To understand the HTTP process, let's ask ourselves, what actually happens each time a user types a URL into a browser in order to open a new webpage. Well the most simple answer is;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The client which in this case is our browser, sends a request to the server in which the web page is located&lt;/li&gt;
&lt;li&gt;The server then sends back a response containing the requested webpage to the client.&lt;/li&gt;
&lt;/ul&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628319887364%2FrYUQx2_0sS.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628319887364%2FrYUQx2_0sS.png" alt="Artboard 233.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This process is called the &lt;strong&gt;Request-Response cycle&lt;/strong&gt;.&lt;br&gt;
Let's take it one step further.&lt;/p&gt;

&lt;p&gt;Let's say we want to access the explore page on hashnode.com by entering the following URL into the browser &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628391128887%2Fhy5-PcNfX.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628391128887%2Fhy5-PcNfX.png" alt="Artboard 2 copy33.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The URL is made up of;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protocol: It is the protocol to be used on the connection, it could be HTTP or HTTPS, in this case, it is HTTPS which is the secure version of HTTP.&lt;/li&gt;
&lt;li&gt;Resource: the resource which we want to access, in this case, it is the explore page &lt;/li&gt;
&lt;li&gt;Domain name: In this case it's hashnode.com, we have to note that the domain name here is not actually the real address of the server that we are trying to access, rather it's just a nice and easy to remember representation of the actual address. So the client needs to convert the domain name to the actual address of the server, through the process of DNS( Domain Name Servers ) Lookup. The actual address of the domain name got from the DNS Lookup is;&lt;/li&gt;
&lt;/ul&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628391189102%2F4vO8rEfFY.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628391189102%2F4vO8rEfFY.png" alt="Artboard 2 copy 233.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This process of DNS Lookup only occurs when the HTTP request is made. &lt;/p&gt;

&lt;p&gt;When a client initiates an HTTP request to the server, it performs the following steps;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It establishes a TCP connection between the client and server: the TCP connection is used to send requests and receive responses&lt;/li&gt;
&lt;li&gt;Once the TCP connection has been established, the client sends an HTTP request message to the server&lt;/li&gt;
&lt;li&gt;After interpreting an HTTP request message the server sends an HTTP response message to the client&lt;/li&gt;
&lt;li&gt;Once the server has responded to the client's request, the TCP connection is closed &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process is illustrated below.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390205455%2FdKcXwfwS8.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390205455%2FdKcXwfwS8.png" alt="Artboard 333.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📝 HTTP messages
&lt;/h2&gt;

&lt;p&gt;There are two types of HTTP messages;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP Request messages sent by the client to the server&lt;/li&gt;
&lt;li&gt;HTTP Response messages sent from the server to the client
each of these messages has a format in which they are generated&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  HTTP Request Message
&lt;/h3&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390747456%2FFhk3an1Va.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390747456%2FFhk3an1Va.png" alt="Artboard 1133.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The request message consists of the following;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTTP method: these methods are usually a verb like 'GET' or 'POST' that defines the operation applied by the client to the resource, in this case, the HTTP method is GET note HTTP methods are case sensitive.&lt;/li&gt;
&lt;li&gt;The Request-URI: identifies the resource upon which the HTTP method is applied. The exact resource is determined using the Request-URI and the Host header field&lt;/li&gt;
&lt;li&gt;The HTTP protocol version: In this case the version is HTTP/1.1&lt;/li&gt;
&lt;li&gt;Request headers: Conveys additional information about the request and about the client itself to the servers, in this case, we have the following request headers;

&lt;ul&gt;
&lt;li&gt;Host: It specifies the internet port(IP) address and port number of the server where the requested resource is stored, an IP address without a trailing port defaults to port number 80 for HTTP requests and 443 for HTTPS requests. Note without specifying the Host header field, the request will return an error&lt;/li&gt;
&lt;li&gt; Accept-Language: Specifies which language the client is able to understand, in this case, the language is 'en' for English, other values could be 'fr' for French&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Body: An optional field that contains the information being sent to the server for storage, mainly used when using HTTP methods like POST, PATCH&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  HTTP Response Message
&lt;/h3&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390735720%2F1Unf9vpWu.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1628390735720%2F1Unf9vpWu.png" alt="Artboard 11 copy33.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The response message consists of the following;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTTP protocol version: In this case the version is HTTP/1.1&lt;/li&gt;
&lt;li&gt;Status code: in this case, is 200&lt;/li&gt;
&lt;li&gt;Response headers: Conveys additional information about the response and about the server itself to the client, in this case, we have the following request headers;

&lt;ul&gt;
&lt;li&gt;Accept-Ranges: It is used by the server to show its support for partial requests&lt;/li&gt;
&lt;li&gt;Server: Describes the software used by the origin by the origin server that handled the request&lt;/li&gt;
&lt;li&gt;Content-type: This header field indicates the resource content type&lt;/li&gt;
&lt;li&gt;E-Tag: it identifies the specific resource version&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Body: An optional field that contains fetched information being sent to the client from the server, mainly used when using HTTP methods like GET.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  HTTP Methods
&lt;/h2&gt;

&lt;p&gt;HTTP uses methods to define the operation to be applied to the resource identified by the Request-URI. These methods are usually verbs, with the most widely used methods being POST, GET, PATCH, and DELETE. Each of these HTTP methods returns a success or failure upon completion of their operations, using status codes to represent success or a failure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GET: This method retrieves the resource specified in the request-URI. If successful the resource is returned as an entity in the response message along with the status code 200 (Success).&lt;/li&gt;
&lt;li&gt;POST: This method request that the server accepts the data or entity enclosed in the Request body, if successful the server responds by sending a response message containing the status code 201 (Created), along with the location of the posted entity or data.&lt;/li&gt;
&lt;li&gt;PUT: This method request that the enclosed data or entity in the Request body be used to modify the request identified by the  Request-URI.&lt;/li&gt;
&lt;li&gt;DELETE: This method request that the enclosed data or entity in the request be stored under the supplied Request-URI.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  📱 HTTP Status Codes
&lt;/h2&gt;

&lt;p&gt;The status codes are used by the client to determine if the HTTP request sent to the server, along with the specified operation was a success or a failure, remember the operation is specified by using the HTTP method.&lt;br&gt;
The status code is a 3 digit result code, with the first digit defining the class of the code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;1xx (Informational): This class of status codes consists of informational responses indicating that a client should continue with a request. Examples of  status codes belonging to this class;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;100 Continue: The client should continue with their request&lt;/li&gt;
&lt;li&gt;101 Switching protocols: The server is willing to comply with the request to change the application protocol being used in the connection, this request is made using the Upgrade message header field&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2XX (Success): This class of status codes indicates that the request made by the client was successfully received, understood, and accepted by the server. Examples of  status codes belonging to this class include the following;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;200 Ok: The request succeeded, the information returned with the response is dependent on the HTTP method used in the request.

&lt;ul&gt;
&lt;li&gt;GET: the requested resource is sent in the response&lt;/li&gt;
&lt;li&gt;POST: A description of the action is sent in the response&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;201 Created: The request has succeeded and a new resource has been created&lt;/li&gt;
&lt;li&gt;202 Accepted: The request has been accepted but not yet processed by the server &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;3XX (Redirection): This class of status codes indicates that further action needs to be taken by the user to complete the request, examples of status codes belonging to this class;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;301 Moved permanently: The requested resource has been moved permanently to a new URI, the permanent URI is given in the Location header field in the response&lt;/li&gt;
&lt;li&gt;304 Not modified: A successful get request is made, but the client does not modify the resource&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;4XX (Client Error): This class of status code indicates that the client has erred. Examples of status codes belonging to this class; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;400 Bad requests: The request could not be understood by the server&lt;/li&gt;
&lt;li&gt;401 Unauthorized: The request requires user authentication&lt;/li&gt;
&lt;li&gt;404 Not found: The server can not find any resource matching the resource-URI
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;5XX (Server Error): This class of status code indicates that the server has erred. Examples of status codes belonging to this class;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500 Internal error: The server encountered an unexpected condition with prevented it from fulfilling the request&lt;/li&gt;
&lt;li&gt;503 Service unavailable: The server is unable to handle the request due to a temporal condition such as server maintenance or temporal overloading&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can read a lot more about status codes  &lt;a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10" rel="noopener noreferrer"&gt;here&lt;/a&gt; &lt;/p&gt;

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

&lt;p&gt;I hope you found this article useful and helpful, if you have any questions let me know in the comments. In a later article, we are going to learn how to implement and use these concepts in building a Rest API. That's it for now 👋&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
