
API in JavaScript: Connecting Your Code to the World
An API (Application Programming Interface) in JavaScript is a way for your code to communicate with other software, services, or systems. In simple words: API = Bridge between your JavaScript and external data/services Real-Time Example In Pharmacy E-Commerce : User clicks “Buy Now” JS sends request to payment API (like Razorpay) API processes payment JS gets response → shows Success / Failed API Methods in JavaScript GET (Read Data) Used to fetch data from server fetch ( " https://api.example.com/products " ) . then ( res => res . json ()) . then ( data => console . log ( data )); POST (Create Data) Used to send new data to server fetch ( " https://api.example.com/products " , { method : " POST " , body : JSON . stringify ({ name : " Tablet " , price : 100 }), headers : { " Content-Type " : " application/json " } }); PUT (Update Full Data) Used to update entire data fetch ( " https://api.example.com/products/1 " , { method : " PUT " , body : JSON . stringify ({ name : " Tablet " , pri
Continue reading on Dev.to Webdev
Opens in a new tab


