1. What is an API?
- API (Application Programming Interface) = a way for applications to communicate.
- In web apps → API acts like a messenger between frontend (browser/mobile app) and backend (server + database).
- Instead of HTML pages, APIs usually return JSON data.
📌 Example:
GET /api/users/123
Response:
{ "id": 123, "name": "Alice", "email": "[email protected]" }
2. REST API Basics
REST (Representational State Transfer) is the most common API style.
- Uses HTTP methods to interact with resources:
GET → Fetch data
POST → Create data
PUT → Update/replace data
PATCH → Modify part of data
DELETE → Remove data
- Returns JSON or XML.
- Each resource has a URL endpoint.
📌 Example:
GET /api/products → Get all products
GET /api/products/10 → Get product with ID 10
POST /api/products → Add a new product
PUT /api/products/10 → Update product 10
DELETE /api/products/10 → Delete product 10
3. GraphQL Basics
- GraphQL = newer API query language (by Facebook).
- Instead of multiple endpoints, you have one endpoint (usually
/graphql).
- Client specifies exact data it wants → prevents over-fetching/under-fetching.