DEV Community

Cover image for JavaScript : Web APIs (English/Hindi)
Dharmik Dholu
Dharmik Dholu

Posted on

JavaScript : Web APIs (English/Hindi)

English

JavaScript Web APIs are sets of functions and tools that allow JavaScript, a programming language mainly used for web development, to interact with and manipulate web-related features and content. These APIs are built into web browsers and provide a way for JavaScript code to access various functionalities like handling user input, making network requests, and modifying the Document Object Model (DOM) of a web page.

For example, let's say you want to fetch data from a web server and display it on your website. You can use the fetch API, which is a part of the Web APIs, to make an HTTP request to the server and retrieve the data. Here's a simplified JavaScript code snippet:

fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => {
    // Do something with the data, like displaying it on your webpage
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
Enter fullscreen mode Exit fullscreen mode

In this code, fetch is a Web API that allows JavaScript to send a request to 'https://api.example.com/data' and handle the response data when it arrives.

Hindi

JavaScript Web APIs JavaScript ke functions aur tools hain jo JavaScript, ek programming language hai jo mainly web development ke liye istemal hoti hai, ko web se judi suvidhao aur content ke saath interact karne aur use manipulate karne ke liye allow karte hain. Ye APIs web browsers mein built-in hote hain aur JavaScript code ko user input ko handle karne, network requests bhejne aur web page ke Document Object Model (DOM) ko modify karne jaise alag-alag functionalities tak pahunchane ka ek tareeka pradan karte hain.

Misaal ke taur par, man lijiye aap ek web server se data fetch karna chahte hain aur use apne website par dikhana chahte hain. Aap fetch API ka istemal kar sakte hain, jo Web APIs ka ek hissa hai, server ko HTTP request bhejne aur data ko retrieve karne ke liye. Niche ek simplified JavaScript code snippet diya gaya hai:

fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => {
    // Data ke saath kuch karna, jaise ki ise apne webpage par dikhana
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
Enter fullscreen mode Exit fullscreen mode

Is code mein, fetch ek Web API hai jo JavaScript ko 'https://api.example.com/data' par ek request bhejne aur jab data aaye to usse handle karne ki anumati deta hai.

Top comments (0)