What is API - Frontend and Backend Connection
What is API
API full form is Application Programming Interface.
API is very important for building big projects in Angular, React, Vue, etc.
Without API knowledge, it is not possible to build a proper project.
Why API is Needed
JavaScript and its frameworks cannot directly connect to the database.
JavaScript code runs in the browser, not on the server.
Database is always on the server.
So, API is used to connect:
- Frontend (browser)
- Backend (server + database)
How API Works
Backend languages like:
- Node.js
- Java
- Python
- PHP
run on the server and connect to the database.
They fetch data from the database and convert it into JSON format.
This JSON data is sent to the frontend using API.
JavaScript easily understands JSON.
API as a Bridge
API works as an interface between frontend and backend.
Flow:
- Database
- Backend (Node / Python / Java)
- API
- Frontend (Angular / React / Vue)
Frontend uses API to get data and display it.
Why Not Build Everything in Backend Only
Backend websites are:
- Slower
- Not single-page
- Page reloads again and again
Modern applications are built for:
- Web
- Mobile apps (Android, iOS)
One API can be used for:
- Web application
- Mobile application
- Desktop application
Backend is written once, frontend can be built many times.
Frontend and Backend Meaning
Frontend:
- Browser
- Mobile applications
Backend:
- Server-side code
- Database
API connects both.
Main Use of API
API is used to:
- Get data from backend
- Send data to frontend
- Share data between backend and frontend