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", price: 120 }),
headers: { "Content-Type": "application/json" }
});
PATCH (Update Partial Data)
Used to update only specific fields
fetch("https://api.example.com/products/1", {
method: "PATCH",
body: JSON.stringify({ price: 120 }),
headers: { "Content-Type": "application/json" }
});
DELETE (Remove Data)
Used to delete data
fetch("https://api.example.com/products/1", {
method: "DELETE"
});
Types of APIs in JavaScript (Quick View)
- Browser APIs → DOM, Geolocation
- Third-party APIs → Payment (Razorpay), Maps
- Custom APIs → Your backend (Python/Node)




Top comments (0)