<?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: Dmitry Polyakov</title>
    <description>The latest articles on DEV Community by Dmitry Polyakov (@dmitrypolyakov1985).</description>
    <link>https://dev.to/dmitrypolyakov1985</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%2F227325%2F79290419-b919-420f-a5c2-eb6f14d8d9a7.jpg</url>
      <title>DEV Community: Dmitry Polyakov</title>
      <link>https://dev.to/dmitrypolyakov1985</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmitrypolyakov1985"/>
    <language>en</language>
    <item>
      <title>AJAX and Fetch explained in simple words</title>
      <dc:creator>Dmitry Polyakov</dc:creator>
      <pubDate>Mon, 18 Nov 2019 02:33:55 +0000</pubDate>
      <link>https://dev.to/dmitrypolyakov1985/ajax-and-fetch-explained-in-simple-words-1o0b</link>
      <guid>https://dev.to/dmitrypolyakov1985/ajax-and-fetch-explained-in-simple-words-1o0b</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%2F2eigiigt9zf8ghxes4ua.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%2F2eigiigt9zf8ghxes4ua.jpg" alt="Alt Text" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;In this article I'd like to share with you 2 simple templates that will help you grab data from servers&lt;/h3&gt;

&lt;p&gt;They are copy-paste ready-to-use templates. Some changes need to be done depending on how you want to use received data. In my examples I explain basic principles of retrieving data from servers just logging it to a console. Everything is explained with simple terms and words.&lt;/p&gt;

&lt;p&gt;All data is stored on servers in JSON format. They are always objects consisting of strings.&lt;/p&gt;

&lt;p&gt;The URL with JSON data that I'm using for my examples is: https://jsonplaceholder.typicode.com/users&lt;/p&gt;

&lt;h1&gt;AJAX / XMLHttpRequest&lt;/h1&gt;

&lt;p&gt;This code sends a GET request to a server. It means that we just receive some data from a server without sending anything back and not modifying any data stored on a server&lt;/p&gt;

&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%2Fuz6xw7otw45f98tb4l9v.jpeg" 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%2Fuz6xw7otw45f98tb4l9v.jpeg" alt="Alt Text" width="567" height="338"&gt;&lt;/a&gt;&lt;br&gt;
On line 1 we save a URL which we are sending our request to.&lt;br&gt;
On line 2 we create a new XMLHttpRequest and give it a name 'xhr'.&lt;br&gt;
On lines 10-11 we open and send our request to a server.&lt;/p&gt;

&lt;p&gt;Inside the function on lines 4-9 we write everything that we want to do with the data that we receive from a server.&lt;/p&gt;

&lt;p&gt;Data is returned from a server as a JSON object. All data inside JSON objects is always a string. To be able to use this data we need to convert it into a JavaScript object using JSON.parse() method. We do that on line 6 and save it into a variable 'res'. Now the data stored in the 'res' variable is an array of JavaScript objects represented by key:value pairs. Each of the objects in our array looks like this:&lt;/p&gt;

&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%2Ffs9zzps2jwuwdth0i92f.jpeg" 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%2Ffs9zzps2jwuwdth0i92f.jpeg" alt="Alt Text" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that we use map() method and a callback function passed in inside map() to iterate over each object inside an array stored in a 'res' variable and grab data that we need.&lt;/p&gt;

&lt;p&gt;The callback function in our case is an arrow function. It's parameter 'item' represents each individual object.&lt;/p&gt;

&lt;p&gt;As we could see in the picture above each object has multiple keys ('address', 'company', 'email', etc). By appending key names to our parameter 'item' we are able to access corresponding values.&lt;/p&gt;

&lt;p&gt;In our example on line 7 we access the key 'name' and log its values from all the objects to a console (item =&amp;gt; console.log(item.name)). The result will be the names from all the object logged to a console one after the other.&lt;/p&gt;

&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%2Fampw7r0aq6ge6mervaqb.jpeg" 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%2Fampw7r0aq6ge6mervaqb.jpeg" alt="Alt Text" width="543" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Fetch&lt;/h1&gt;

&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%2Feo3thf6zmco1iw0klief.jpeg" 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%2Feo3thf6zmco1iw0klief.jpeg" alt="Alt Text" width="619" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we send a request to a server using fetch() method we receive a JSON object and save it in a variable 'res'. You can give a variable any name you like. Make sure that you don't put semicolon after fetch().&lt;/p&gt;

&lt;p&gt;On the next line we append a .then() method to our fetch() request. .then() method grasps data returned on the previous step, does something new with it and returns the result. To handle this returned data we pass in a callback function inside .then(). In our first .then() we convert JSON object into JavaScript object (res =&amp;gt; res.json()).&lt;/p&gt;

&lt;p&gt;After that we append another .then(). The second .then() grasps the data returned by the previous .then(), which is an array of JavaScript objects, iterates over all objects and logs all the name to a console.&lt;/p&gt;

&lt;p&gt;The final result in a console will be absolutely identical to what we saw when we sent a AJAX/XMLHttpRequest above.&lt;/p&gt;

</description>
      <category>api</category>
      <category>fetch</category>
      <category>json</category>
      <category>ajax</category>
    </item>
    <item>
      <title>How to fix a footer at the bottom of the page</title>
      <dc:creator>Dmitry Polyakov</dc:creator>
      <pubDate>Mon, 30 Sep 2019 03:34:12 +0000</pubDate>
      <link>https://dev.to/dmitrypolyakov1985/how-to-fix-a-footer-at-the-bottom-of-the-page-3hhi</link>
      <guid>https://dev.to/dmitrypolyakov1985/how-to-fix-a-footer-at-the-bottom-of-the-page-3hhi</guid>
      <description>&lt;p&gt;I believe all beginning developers at some point come across this problem while building web pages. Sometimes you have too little content on your page, then your footer ‘jumps up’ and follows the rest of the content somewhere in the center of a page. See picture below.&lt;/p&gt;

&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%2Fzl23k8nxkulkrykoelse.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%2Fzl23k8nxkulkrykoelse.jpg" alt="Footer doesn't stick to the bottom" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ll share with you an easy way how to fix that step by step. &lt;/p&gt;

&lt;p&gt;Markup of the page is very simple. Inside the body we have a main section and a footer. The main section contains a heading and a paragraph with some lorem ipsum text to fill in some space. As we can see the footer is in the middle of the page.&lt;/p&gt;

&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%2Fjel9miq44bodd19ifdwa.jpeg" 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%2Fjel9miq44bodd19ifdwa.jpeg" alt="html markup" width="800" height="662"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want you footer to be attached to the bottom of the screen and you are not going to change its content a lot you can give it a fixed height. My footer is 35px high. Basic styling is below.&lt;/p&gt;

&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%2Fcevrmvvr6nxbc231u9xe.jpeg" 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%2Fcevrmvvr6nxbc231u9xe.jpeg" alt="Footer basic styles" width="269" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need just 3 lines of code to force it to the bottom of the page.&lt;/p&gt;

&lt;p&gt;To do that we need to give our footer a position of fixed, this will take it out of the normal flow of the document. After that we can place it anywhere on the page, in our case we change its position to 0px from the bottom and 0px from the left.&lt;/p&gt;

&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%2Fyku6snv0xbmf4y8nr639.jpeg" 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%2Fyku6snv0xbmf4y8nr639.jpeg" alt="Footer final styles" width="269" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our footer is attached to the bottom of the page.&lt;/p&gt;

&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%2Fg5ks1t4ng7w7lu0xbs46.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%2Fg5ks1t4ng7w7lu0xbs46.jpg" alt="Footer sticks to the bottom" width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We might think we are done now. Not yet…&lt;/p&gt;

&lt;p&gt;As we add more content onto the page we get into trouble. In our case I’ll add more lorem ipsum text so that it reaches the bottom. As we do that we find out that we don’t see the end of the lorem ipsum text. The footer is overlapping it. Even if you scroll to the very bottom of the page some part of the text is covered by the footer.&lt;/p&gt;

&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%2Fotqfmbyrxtsfk6d7z7ls.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%2Fotqfmbyrxtsfk6d7z7ls.jpg" alt="Text covered by the footer" width="800" height="662"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can be fixed with one line of code.&lt;/p&gt;

&lt;p&gt;We know that our footer is 35px high. It means that to be able see all the content of the section that goes before the footer we need to move the bottom of that section up by 35px. We can do that by giving our main section a margin-bottom of 35px. This way the bottom edge of our main section and the top edge of the footer are not overlapping any more, they are now attached to each other, and the content is not covered by the footer.&lt;/p&gt;

&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%2Ffc10lqq6j42aq4ti0h8o.jpeg" 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%2Ffc10lqq6j42aq4ti0h8o.jpeg" alt="Main final styles" width="294" height="193"&gt;&lt;/a&gt;&lt;br&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%2F5gcy2sglcjg5sh8854fs.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%2F5gcy2sglcjg5sh8854fs.jpg" alt="Final print screen, text is not covered by the footer" width="800" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my first article that I wrote with the intention to help beginning developers to find easy solutions to common issues that 100% of beginners face.&lt;/p&gt;

&lt;p&gt;Hopefully I’ll help you make your life easier.&lt;/p&gt;

&lt;p&gt;More article to follow…&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
