<?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: Aoun Abbas Kherani</title>
    <description>The latest articles on DEV Community by Aoun Abbas Kherani (@abbaskherani).</description>
    <link>https://dev.to/abbaskherani</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%2F1963410%2Ffdd96c2a-567b-4988-bb83-daf84f843970.jpeg</url>
      <title>DEV Community: Aoun Abbas Kherani</title>
      <link>https://dev.to/abbaskherani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abbaskherani"/>
    <language>en</language>
    <item>
      <title>"Master these 11 Web APIs - Essential Knowledge for Every Developer!"</title>
      <dc:creator>Aoun Abbas Kherani</dc:creator>
      <pubDate>Tue, 27 Aug 2024 09:56:29 +0000</pubDate>
      <link>https://dev.to/abbaskherani/master-these-11-web-apis-essential-knowledge-for-every-developer-3i2b</link>
      <guid>https://dev.to/abbaskherani/master-these-11-web-apis-essential-knowledge-for-every-developer-3i2b</guid>
      <description>&lt;p&gt;As a web developer, understanding and utilizing key &lt;strong&gt;Web APIs&lt;/strong&gt; can greatly enhance the functionality and user experience of your applications.&lt;/p&gt;

&lt;p&gt;Here are 12 essential Web APIs that you should know:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Storage API
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Web Storage API&lt;/strong&gt; provides two key storage mechanisms for handling data directly in the browser. &lt;strong&gt;localStorage and sessionStorage&lt;/strong&gt;. Both are used to store data in the form of key-value pairs, which are like labels (keys) and their associated data (values).&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;localStorage stores data that should persist even after the browser is closed and reopened&lt;/strong&gt;. This means the data stays there until you explicitly delete it, making it useful for saving user preferences, login states, or other settings that you want to retain across sessions.&lt;/p&gt;

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

&lt;p&gt;sessionStorage is for &lt;strong&gt;storing data only for the duration of a page session&lt;/strong&gt;. This means the data is available as long as the browser tab or window is open. Once you close the tab or window, the data is cleared.&lt;/p&gt;

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

&lt;p&gt;IndexedDB is a &lt;strong&gt;low-level API for storing significant amounts of structured data&lt;/strong&gt;, such as objects and large datasets, directly in the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ideal for complex applications&lt;/strong&gt; requiring offline storage, such as large-scale apps or offline-enabled features. It allows for efficient querying and indexing of data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cookie Store API:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Cookie Store API is a modern interface for &lt;strong&gt;managing cookies in a more structured and convenient way&lt;/strong&gt; compared to traditional cookie handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Useful for handling small amounts of data&lt;/strong&gt; that need to be sent back to the server with each HTTP request, like session tokens or user preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Payment Request API
&lt;/h2&gt;

&lt;p&gt;The Payment Request API provides a &lt;strong&gt;standardized way for web applications&lt;/strong&gt; to request and process payments from users, making online payments faster and more user-friendly.&lt;/p&gt;

&lt;p&gt;Key features includes &lt;strong&gt;simplifying checkout, providing a native payment interface and handling secure payment flow&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example Use Case:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A user shopping online reaches the checkout page. Instead of entering card details manually, the API allows the user to select a payment method from their saved payment history simplifying the payment process.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. DOM API
&lt;/h2&gt;

&lt;p&gt;The DOM API provides a way to programmatically &lt;strong&gt;access and modify the elements, attributes, and content of a web page&lt;/strong&gt;. It represents the web page as a tree of objects, where each object corresponds to a part of the page (like elements, text, and attributes).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Commonly used methods and properties:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;document.getElementById(id)&lt;/code&gt;: Retrieves an element by its unique ID.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;document.querySelector(selector)&lt;/code&gt;: Selects the first element that matches a CSS selector.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;element.innerHTML&lt;/code&gt;: Gets or sets the HTML content inside an element.&lt;/p&gt;

&lt;p&gt;In summary, the DOM API enables developers to interact with and &lt;strong&gt;manipulate the content and structure of web pages dynamically&lt;/strong&gt;, enhancing the interactivity and functionality of websites.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. HTML Sanitizer API
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;HTML Sanitizer API&lt;/strong&gt; is a web standard designed to safely handle and clean &lt;strong&gt;user-generated HTML&lt;/strong&gt; content before it's displayed on a web page. Its primary goal is to prevent security vulnerabilities, such as &lt;strong&gt;Cross-Site Scripting (XSS) attacks&lt;/strong&gt;, by ensuring that any potentially harmful code is removed or neutralized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customizable rules&lt;/strong&gt;, &lt;strong&gt;Automatic Sanitization&lt;/strong&gt; and &lt;strong&gt;preventing malicious code&lt;/strong&gt; from being executed are some key features of the Sanitizer API.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Canvas API
&lt;/h2&gt;

&lt;p&gt;The Canvas API lets you &lt;strong&gt;create graphics and animations dynamically on a web page&lt;/strong&gt;. You use it to draw and modify visual content like lines, shapes, and images in real-time.&lt;/p&gt;

&lt;p&gt;It is a part of HTML5 that allows you to &lt;strong&gt;draw and manipulate graphics directly on a web page using JavaScript&lt;/strong&gt;. Think of it as a blank sheet of paper where you can draw shapes, text, and images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Canvas Example&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"myCanvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"border:1px solid #000000;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. History API
&lt;/h2&gt;

&lt;p&gt;The History API is a set of methods in JavaScript that allows you to &lt;strong&gt;manipulate the browser's history&lt;/strong&gt; and URL without reloading the page. It's &lt;strong&gt;useful for creating single-page applications (SPAs)&lt;/strong&gt; where you want to update the URL and &lt;strong&gt;handle navigation without refreshing the whole page&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Javascript methods:&lt;/strong&gt;
&lt;code&gt;pushState()&lt;/code&gt;: Adds a new entry to the browser history with a new URL.
&lt;code&gt;replaceState()&lt;/code&gt;: Updates the current history entry with a new URL.
&lt;code&gt;popstate&lt;/code&gt; Event: Lets you handle changes to the history state, such as when users navigate using back/forward buttons.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The History API helps in creating smooth, dynamic web applications by allowing you to manage navigation and URL changes without page reloads, enhancing the user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Clipboard API:
&lt;/h2&gt;

&lt;p&gt;The Clipboard API is a &lt;strong&gt;JavaScript interface that allows web applications to interact with the clipboard&lt;/strong&gt;, the temporary storage area for copying and pasting data. It makes it easier to programmatically copy text to the clipboard and read text from it.&lt;/p&gt;

&lt;p&gt;The Clipboard API simplifies working with clipboard operations, making it easy to integrate &lt;strong&gt;copy-and-paste functionality&lt;/strong&gt; into your web applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Copying text to the clipboard:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use the Clipboard API to copy text to the clipboard. This is useful for creating features like "Copy to Clipboard" buttons.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reading text from the clipboard:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly, you can read text that a user has copied to the clipboard. This can be used for pasting content into a web application.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Fullscreen API:
&lt;/h2&gt;

&lt;p&gt;The Fullscreen API is a web development tool that enables elements on your webpage to occupy the entire screen, making it perfect for immersive experiences like games, video players, or data visualizations.&lt;br&gt;
It helps expand a specific element(sometimes an entire page) to fill the user's screen, also hiding the browser UI elements and offering a more engaging experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Javascript Methods:&lt;/strong&gt;
Mostly used APIs for full-screen view are &lt;code&gt;document.exitFullscreen&lt;/code&gt;, &lt;code&gt;document.webkitExitFullscreen&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  9. FormData API:
&lt;/h2&gt;

&lt;p&gt;When you are building web apps, it's important to handle form data effectively. The FormData API gives you a strong and flexible way to work with form data in your code. &lt;strong&gt;Whether you are collecting user input, sending it to a server, or changing it before submission.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The FormData API allows you to easily **construct key/value pairs **representing form fields and their values. This data can be sent using the &lt;code&gt;fetch&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy form Handling, flexibility and powerful integration&lt;/strong&gt;(fetch API) are some reasons to consider using FormData API.&lt;/p&gt;
&lt;h2&gt;
  
  
  10. Fetch API:
&lt;/h2&gt;

&lt;p&gt;The Fetch API is a modern JavaScript interface that &lt;strong&gt;simplifies sending HTTP requests and handling responses&lt;/strong&gt;, offering a cleaner and more powerful alternative to older methods like XMLHttpRequest.&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// or response.text(), response.blob(), etc.&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;fetching data:&lt;/strong&gt; Receiving data from an API and processing the response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sending data:&lt;/strong&gt; Post data to a server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-&lt;strong&gt;Handling form data:&lt;/strong&gt; Submit forms with &lt;code&gt;FormData&lt;/code&gt; API with &lt;code&gt;fetch&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fetch&lt;/code&gt; API using promise-based simplifies working with asynchronous operations. Whether you're retrieving data, sending forms, or streaming content, use &lt;code&gt;fetch&lt;/code&gt; for flexibility and ease of use.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Geolocation API:
&lt;/h2&gt;

&lt;p&gt;The Geolocation API provides methods to get the &lt;strong&gt;geographical position of a user’s device&lt;/strong&gt;. It is built into most modern web browsers and works on both desktop and mobile devices.&lt;/p&gt;

&lt;p&gt;This can be useful for providing local weather or even updating your feed to show nearby restaurants, parks and much more.&lt;/p&gt;

&lt;p&gt;By retrieving location we get the user's longitude, latitude, altitude and more.&lt;br&gt;
We can also watch real-time locations as they move.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Javascript Methods:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;navigator.geolocation.getCurrentPosition()&lt;/code&gt; - To get the user's &lt;strong&gt;current geographical location&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;navigator.geolocation.watchPosition()&lt;/code&gt; - To &lt;strong&gt;continuously track the user's location&lt;/strong&gt; whenever the user's position changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mastering these APIs&lt;/strong&gt; will elevate your web development skills, allowing you to create more &lt;strong&gt;interactive, efficient&lt;/strong&gt;, and &lt;strong&gt;user-friendly applications&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What other APIs should developers be aware of? Don't forget to comment below.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
