Frontend and backend code run in completely different places — the browser and the server — and communicate over HTTP.

The Request Cycle

The browser sends an HTTP request to a URL; the backend processes it and returns a response, usually as JSON for APIs or HTML for full page loads.

Fetching Data

javascript
fetch("/api/products")
  .then(res => res.json())
  .then(data => console.log(data));

CORS

Cross-Origin Resource Sharing (CORS) is a browser security rule that blocks requests to a different domain unless the server explicitly allows it via response headers.

http
Access-Control-Allow-Origin: https://devqura.com
Access-Control-Allow-Methods: GET, POST

Putting It Together

A typical flow: the frontend calls /api/products, the backend queries a database, formats the result as JSON, and the frontend renders it into the page.

ConceptsAPIFrontendBackend