<?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>Forem: abdul waheed</title>
    <description>The latest articles on Forem by abdul waheed (@waheed38).</description>
    <link>https://forem.com/waheed38</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%2F220570%2F5a003262-806c-4815-9f42-468ed010b949.jpg</url>
      <title>Forem: abdul waheed</title>
      <link>https://forem.com/waheed38</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/waheed38"/>
    <language>en</language>
    <item>
      <title>What is Libp2p?</title>
      <dc:creator>abdul waheed</dc:creator>
      <pubDate>Sat, 05 Sep 2020 11:31:12 +0000</pubDate>
      <link>https://forem.com/waheed38/what-is-libp2p-319b</link>
      <guid>https://forem.com/waheed38/what-is-libp2p-319b</guid>
      <description>&lt;p&gt;We depend on the Internet for everything, right ? A cliche line. &lt;br&gt;
While that is true, in literal meaning  we are using networks which are centralized and unsecured.&lt;br&gt;
So we need to move to more resilient and secure networks.&lt;/p&gt;

&lt;p&gt;Peer to Peer Networks ( P2P)  and networking is the way that we can create such secure and resilient networks. Many libraries and tools are being and have been developed to help this ecosystem. One of these libraries is Libp2p.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Libp2p?
&lt;/h4&gt;

&lt;p&gt;Libp2p is an open source library that was developed while building &lt;a href="https://ipfs.io/"&gt;IPFS&lt;/a&gt;. &lt;br&gt;
Contributors of this project took care to build the solution in a modular and composable way. Now Libp2p has grown out of &lt;a href="https://ipfs.io/"&gt;IPFS&lt;/a&gt;, it does not require or depend on IPFS, and today many projects use Libp2p as their network transport layer. &lt;/p&gt;

&lt;p&gt;Libp2p is implemented in many popular languages, at the time of writing this article it is being implemented in Javascript, Node Js, Rust and Go.&lt;/p&gt;

&lt;p&gt;According to official documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;" Libp2p is a modular system of protocols, specifications and libraries that enable the development of peer-to-peer network applications."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s see what we understand from this definition and what we achieve with this library.&lt;/p&gt;

&lt;p&gt;Modularity is a key feature of Libp2p, meaning every module is designed to do a specific task and we can use only what we need.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://www.blogger.com/blog/post/edit/7491733402634136650/8065616143919457163#"&gt;Transport&lt;/a&gt;:
&lt;/h4&gt;

&lt;p&gt;This module is responsible for sending and receiving data from peers through a node. It supports most of the available protocols and also provides simple interfaces to use and run different environments and networks. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://www.blogger.com/blog/post/edit/7491733402634136650/8065616143919457163#"&gt;Ping&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This module is used to ping any peer in the network by knowing the Identity of that peer. It can return RTT(Return Response Time) or Error that either peer is not found or is offline.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://www.blogger.com/blog/post/edit/7491733402634136650/8065616143919457163#"&gt;Circuit&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Circuit modules provide a way to create connections between peers.  It uses a public IP address as a middleware. This middleware transports data to each other. &lt;/p&gt;

&lt;p&gt;There are many other modules available, you can find them on &lt;a href="https://pkg.go.dev/search?q=libp2p"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Libp2p handles Authentication, Transports, Stream Multiplexing, Peer Discovery, Peer Routing, Content Routing, NAT Traversal, and Relay, you can study more about these protocols on Docs.&lt;/p&gt;

&lt;p&gt;Specifications are set of standards defined and used during building of Libp2p irrespective of  language or implementation. They are categorized into two main classes :&lt;/p&gt;

&lt;p&gt;*Core Specifications&lt;br&gt;
*Protocols Specifications. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Core Specifications&lt;/strong&gt; contain detailed description of Libp2p core functionality.How connection is established between two peers, and What is the Protocol Negotiation. Libp2p uses a process of streams for communication of data, either peer can open the stream after connection is established. Also defines the state of any connection stored and peer metadata stored in a memory for future use. It also defines the available cryptographic algorithm for the generation of peer id and encryption of data.You can check more details from this &lt;a href="https://docs.libp2p.io/"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protocol Specifications&lt;/strong&gt; define wire protocols that are used for multiplexing, security, peer discovery and many others. You can check more details from this repository.&lt;/p&gt;

&lt;p&gt;What we can do with this Library,  Libp2p has a generalized toolkit so that developers can plug and play with their networking stack while building distributed applications. &lt;/p&gt;

&lt;p&gt;If you are following Ethereum 2.0, Filecoin and Polkadot then you know that they are already using Libp2p for networking stack.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Libp2p is an open source network transport layer that can make our network more secure and resilient, with its modular structure it is easy to incorporate in our project with only need based use of its elements. &lt;/p&gt;

</description>
      <category>p2p</category>
      <category>web3</category>
      <category>ethereum</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Global HTTP Request using Interceptors and Axios</title>
      <dc:creator>abdul waheed</dc:creator>
      <pubDate>Sat, 05 Sep 2020 10:46:35 +0000</pubDate>
      <link>https://forem.com/waheed38/global-http-request-using-interceptors-and-axios-9m3</link>
      <guid>https://forem.com/waheed38/global-http-request-using-interceptors-and-axios-9m3</guid>
      <description>&lt;h4&gt;
  
  
  What are Interceptors?And how to intercept axios request and response.
&lt;/h4&gt;

&lt;p&gt;If for some reason you want to inject a piece of code in a method that needs to be executed before or after the execution of that method, then interceptors are there to help you. In the following example, we created an interceptor method on Array.prototype.reverse, this method consoles the value of the array before the reverse and after the reverse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// store original implementation in cache
var _reverse = Array.prototype.reverse;

// define your own reverse method
Array.prototype.reverse = function() {

   // before reversing array
   console.log("before reverse \n"+this.toString());

   // call original Array reverse method
   _reverse.apply(this, arguments );

   // do whatever you like after
   // the reverse has been called
       console.log("after reverse\n"+this.toString());
}

const array1 = ['one', 'two', 'three'];

array1.reverse();
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Intercept axios request
&lt;/h4&gt;

&lt;p&gt;For those who do not  know what is axios? “ Axios is a promise based HTTP client for the browser and node.js.” With the help of interceptors we can modify the request and response before respective methods calls from the library. Interceptors can help us apply common functionality across all requests at one place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const HTTP = axios.create({
 baseURL: env.API_URL,
 timeout: 60000,
});

HTTP.interceptors.request.use(
 (config) =&amp;gt; {
  config.headers.authorization = `Bearer ${localStore.getToken()}`;
   return config;
 },
 (error) =&amp;gt; {
   return Promise.reject(error);
 }
);

// Add a response interceptor
HTTP.interceptors.response.use(
 (response) =&amp;gt; {
   return response;
 },
 (err) =&amp;gt; {
        console.log(err)
 }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As from the above example we can see that we created an axios instance and use two interceptors one for request and one for response. In the request interceptor we get the token from local storage and put in a header of request and in case if an error occurred during getting token it will reject the request immediately. Another one for the response, it also has two callbacks one for the response(any status code lies between 2xx) and another one for error handling.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
