<?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: Ldakanno</title>
    <description>The latest articles on DEV Community by Ldakanno (@ldakanno).</description>
    <link>https://dev.to/ldakanno</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%2F883631%2F4a0430ae-1b3b-4ec5-8da0-e70bdb4fffd8.jpeg</url>
      <title>DEV Community: Ldakanno</title>
      <link>https://dev.to/ldakanno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ldakanno"/>
    <language>en</language>
    <item>
      <title>Making a POST request using json-server</title>
      <dc:creator>Ldakanno</dc:creator>
      <pubDate>Sun, 11 Dec 2022 08:49:39 +0000</pubDate>
      <link>https://dev.to/ldakanno/making-a-post-request-using-json-server-h7c</link>
      <guid>https://dev.to/ldakanno/making-a-post-request-using-json-server-h7c</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpnhobo5cwakcab5v9y5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpnhobo5cwakcab5v9y5.jpg" alt="Funny relatable programming tweet" width="700" height="876"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Welcome
&lt;/h1&gt;

&lt;p&gt;Hi everyone, it has definitely been a while. This tutorial is mainly for beginners like myself, and by creating this post, I will refresh my knowledge to solidify my skills. Many of you already know how to do these things, but hopefully someone out there can find this post useful. For my current React project that I am working on, I need to incorporate a GET request and a POST request as some of the requirements. In my last blog post, I wrote about how to use json-server. Well, now we are gonna learn how to make a POST request! It will be very exciting, and this blog post will also serve as a brain refresher for me. So once you have json-server set up (refer to my last post if you don't know how), you are going to run it by typing into your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ json-server --watch db.json&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  POST Request Basics
&lt;/h1&gt;

&lt;p&gt;Once your json-server is set up and has some data, you are going to create a basic POST request. There are a few requirements to make a post request. Alongside the URL you will be posting to, you need to also have a configuration object that will pretty much explain what the post request will be. For visual aid, here is a basic example of what a post request will look like:&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_HERE, {
    method: 'POST',
    headers: {
       'Content-Type': 'application/json',
    }
    body: JSON.stringify({
       'ID': 2,
       'Name': 'John',
       'lastName': 'Doe'
    })
}).then(response =&amp;gt; response.json())
.then(console.log(newPerson)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What is all that?
&lt;/h1&gt;

&lt;p&gt;It is very important to have a body in your configuration object when making a POST request. Just think about it, how can you try to POST something, when the server does not know what you want to POST? It is simply not possible. This configuration object will tell the server important information on what you want to POST. Again, this is a pretty basic outline. You can maybe apply this particular example I created to some sort of function that adds a new employee to a database. Another important thing to note is the method. Whenever you make a fetch request that does not include a configuration object, it is automatically interpreted as a GET request. To make any request other than GET, you will have to specify the method in which you are trying to use, in this example it would be POST since we are making a POST request. The header will communicate what kind of data we will be sending. The JSON.stringify method is really neat. It converts a javascript object into a JSON string. We need to do this in order to communicate with the server. Further along, you will see .then() twice. The first instance is to return a promise object. The last .then, in our particular example, will just print out the data into the console. This is especially handy to do in order to check if the POST was made correctly. Obviously, you can manipulate the data however you need. For example, with this particular instance you can display the new employee onto the home page of a web application if you wanted to. Congratulations, you just  learned how to make a basic POST request using JSON-server! &lt;/p&gt;

</description>
      <category>welcome</category>
    </item>
    <item>
      <title>First Big Project / Learning How To Use JSON server</title>
      <dc:creator>Ldakanno</dc:creator>
      <pubDate>Fri, 02 Sep 2022 23:27:37 +0000</pubDate>
      <link>https://dev.to/ldakanno/first-big-project-learning-how-to-use-json-server-1b5</link>
      <guid>https://dev.to/ldakanno/first-big-project-learning-how-to-use-json-server-1b5</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AZVWrIyM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdtt8hgogf453de38ean.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AZVWrIyM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdtt8hgogf453de38ean.jpeg" alt="relatable meme" width="683" height="384"&gt;&lt;/a&gt;&lt;br&gt;
Hello to whoever that has decided to read this! I gotta throw you an update on my learning progress. I finished my first big project, so strap in and get ready to see some beginner programming. Yes, it's okay to laugh and cringe. I'll show you my project and get into how you can set up a JSON server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ViU3oti2t2z1sJb0DH/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ViU3oti2t2z1sJb0DH/giphy.gif" alt="full scroll" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may have noticed I am a huge fan of Avatar the Last Airbender (&lt;em&gt;Nickelodeon, please don't come for me, I'm poor&lt;/em&gt;). This web application is inspired by Uncle Iroh's tea shop in Ba Sing Se. I admire Iroh's character a lot, so I really tried to pay my respects by not making a complete pile of garbage. My main focus was the JavaScript, and to save time I used &lt;a href="https://materializecss.com/"&gt;Materialize&lt;/a&gt;. If Materialize was a person, I'd kiss them. It is such a handy-dandy CSS framework!&lt;/p&gt;
&lt;h2&gt;
  
  
  API Hunting
&lt;/h2&gt;

&lt;p&gt;I struggled a lot on finding an API that met my needs for what I had envisioned. So, I decided to just make my own data and use JSON server. I am a strong independent programmer, and I don't need to rely on a free public API! Okay, jokes aside, here's what I created based on my vision: &lt;/p&gt;

&lt;p&gt;Here is the submit form being used as a search bar: &lt;br&gt;
&lt;a href="https://i.giphy.com/media/mq7PrpXWcH9ipVGups/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/mq7PrpXWcH9ipVGups/giphy.gif" alt="submit form" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the click events I have in the footer of the web application:&lt;br&gt;
&lt;a href="https://i.giphy.com/media/WUCVSuuVQ9kv10y8MB/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/WUCVSuuVQ9kv10y8MB/giphy.gif" alt="click events" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When setting up a JSON server, you need to make sure you install it locally. You can visit &lt;a href="https://www.npmjs.com/package/json-server"&gt;here&lt;/a&gt; to do that! Then, in the directory you are working on, you need to create a db.json file to store your data. In this file, you will need to use the correct JSON format when inputing the data. JSON syntax looks very much like a typical JavaScript object, but not quite the exact same. Yes, it has brackets and key/value pairs, so naturally it will be comforting to see some sort of familiarity when you first encounter JSON.&lt;/p&gt;

&lt;p&gt;Here is an idea of how I formatted my db.json file, and hopefully it can give you a basic idea on how to format your own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Black Tea"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://media.istockphoto.com/photos/black-tea-in-a-cup-picture-id475614605?b=1&amp;amp;k=20&amp;amp;m=475614605&amp;amp;s=612x612&amp;amp;w=0&amp;amp;h=rJ47IWDVx0UqSjWs_YlZCsN-cyXRLbtW-CMTQUmHnMs="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Often sold in a blend of some sort, the flavor depends on the location the plant was grown and the blend it is sold in. Consisting of many varieties, it is the most common type of tea. It supports heart health and boosts the body's defense towards oxidative stress."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavorProfile"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"strong, dark"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an example of a singular data object that you would find wrapped in brackets alongside other similar objects, all separated by commas. In JSON format, objects are wrapped in curly braces, and separated by commas. Square brackets are used to hold arrays, so keep this all in mind when creating your data. Find a structure that is easy for you to work with. &lt;/p&gt;

&lt;p&gt;Once you have your data in the proper format, get it running!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ json-server --watch db.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you visit your localhost url, you will be greeted by the most comforting text face along with supportive words that remind you that you are doing just fine. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KCaW-zxx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EZnShUEUYAAgD9X.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KCaW-zxx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EZnShUEUYAAgD9X.png" alt="JSON congrats" width="880" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>First Blog Post!</title>
      <dc:creator>Ldakanno</dc:creator>
      <pubDate>Sat, 09 Jul 2022 20:48:26 +0000</pubDate>
      <link>https://dev.to/ldakanno/first-blog-post-3gpm</link>
      <guid>https://dev.to/ldakanno/first-blog-post-3gpm</guid>
      <description>&lt;p&gt;Hello to whoever takes the time to read this! Thank you, and welcome to my first blog post. Right now I am an absolute beginner when it comes to software engineering, so please be gentle ( ﾟヮﾟ). I've also never blogged before, so forgive me if my posts are boring. Since this first post is more of an introduction, I will not be diving into any progress with my studies just yet. Stay tuned! ʕ ·ᴥ· ʔ &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>javascript</category>
      <category>introduction</category>
    </item>
  </channel>
</rss>
