<?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: mishrasatyam</title>
    <description>The latest articles on DEV Community by mishrasatyam (@mishrasatyam).</description>
    <link>https://dev.to/mishrasatyam</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%2F359974%2F453bb591-6b1d-4ce5-9e86-d0fce5defd49.png</url>
      <title>DEV Community: mishrasatyam</title>
      <link>https://dev.to/mishrasatyam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mishrasatyam"/>
    <language>en</language>
    <item>
      <title>Request using node-fetch with async/await</title>
      <dc:creator>mishrasatyam</dc:creator>
      <pubDate>Tue, 20 Oct 2020 08:08:12 +0000</pubDate>
      <link>https://dev.to/mishrasatyam/request-using-node-fetch-with-async-await-30pl</link>
      <guid>https://dev.to/mishrasatyam/request-using-node-fetch-with-async-await-30pl</guid>
      <description>&lt;p&gt;You might have used fetch on client side applications. To use fetch on server side we can use &lt;a href="https://www.npmjs.com/package/node-fetch"&gt;node-fetch&lt;/a&gt; library. Let me show basic examples using async/await .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GET request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetch = require('node-fetch');
async function get_request(){
  const url = 'http://get-request-url.com'
  const res = await fetch(url);
  const data = await res.json();//assuming data is json
  console.log(data)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;POST request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetch = require('node-fetch');
async function post_request(){
  const url = 'http://post-request-url.com'
  const body = {some_var:"some_value"}
  const res = await fetch(url,{method:'POST',body:JSON.stringify(body),headers: { 'Content-Type': 'application/json' }});
  const data = await res.json();//assuming data is json
  console.log(data)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>javascript</category>
      <category>fetch</category>
    </item>
  </channel>
</rss>
