Middle
Who exactly sends requests to the backend on the client side?
sobes.tech AI
Answer from AI
On the client side, requests to the backend are usually sent by code responsible for server interaction — these can be:
- JavaScript functions using
fetch,XMLHttpRequest, or libraries like Axios. - In SPA frameworks (React, Vue, Angular) — services or hooks that encapsulate request logic.
For example, in React, a separate API service is often created:
// api.js
export function fetchUserData(userId) {
return fetch(`/api/users/${userId}`).then(res => res.json());
}
And it is called from components or effects. Thus, it is the client-side code (JavaScript) that initiates requests to the server.