TGViewer
Web Development Web Development @webdevcoursefree ยท 79.6K subscribers
Post #3586 3.73K
๐Ÿ”— Connecting React Frontend to Backend API

Now you connect React (Frontend) with Node.js/Express (Backend). This is the core of full-stack development. Frontend sends HTTP requests โ†’ Backend processes โ†’ Returns JSON data.

๐Ÿง  How Frontend and Backend Communicate

Flow:
1๏ธโƒฃ React sends request (API call)
2๏ธโƒฃ Backend receives request
3๏ธโƒฃ Backend processes logic
4๏ธโƒฃ Backend sends response
5๏ธโƒฃ React updates UI

Example: React โ†’ GET /users โ†’ Express API โ†’ JSON โ†’ React UI

๐ŸŒ API Request Methods Used in React

- GET: Fetch data
- POST: Send data
- PUT: Update data
- DELETE: Remove data

โšก Method 1: Fetch API

JavaScript has a built-in function called fetch().

๐Ÿ“ฅ Example: Fetch users from backend

Backend endpoint: GET http://localhost:3000/users

React code:
import { useEffect, useState } from "react";

function App() {
const [users, setUsers] = useState([]);

useEffect(() => {
fetch("http://localhost:3000/users")
.then(res => res.json())
.then(data => setUsers(data));
}, []);

return (
<div>
<h2>User List</h2>
{users.map(user => (
<p key={user.id}>{user.name}</p>
))}
</div>
);
}

export default App;

Result: React automatically displays backend data.

โž• Sending Data to Backend (POST)

Example: Add new user.
const addUser = async () => {
await fetch("http://localhost:3000/users", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ name: "Deepak" })
});
};

Backend receives JSON and stores it.

โœ๏ธ Updating Data (PUT)
await fetch("http://localhost:3000/users/1", {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ name: "Updated Name" })
});

โŒ Deleting Data (DELETE)
await fetch("http://localhost:3000/users/1", {
method: "DELETE"
});

๐Ÿงฉ Common Full Stack Folder Structure
project/
โ”œโ”€โ”€ client/ (React frontend)
โ”‚ โ””โ”€โ”€ src/
โ”œโ”€โ”€ server/ (Node backend)
โ”‚ โ””โ”€โ”€ routes/
โ”œโ”€โ”€ package.json

Frontend and backend run separately.

โš ๏ธ Common Beginner Issues

1๏ธโƒฃ CORS error
Backend must allow frontend.
Example:
const cors = require("cors");
app.use(cors());

Install: npm install cors

2๏ธโƒฃ Wrong API URL
Frontend must call: http://localhost:3000/api/users

3๏ธโƒฃ Missing JSON middleware
app.use(express.json())

๐Ÿงช Mini Practice Task

Build a simple React + Express full stack app
Tasks:
- Fetch users from backend
- Display users in React
- Add new user from React form
- Delete user from UI

โžก๏ธ Double Tap โ™ฅ๏ธ For More
  • โค 15
More from @webdevcoursefree
  1. Oct 14, 2026๐ŸŒ Web Development Roadmap โ€” Part 17 HTML Images โ€” <img> Tag Images make webpages more visโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 2026For example: Go to Profile โ†’ <a> Submit Form โ†’ <button> Open Article โ†’ <a> Delete Accountโ€ฆ
  4. Oct 12, 2026๐ŸŒ Web Development Roadmap โ€” Part 16 HTML Links โ€” Tag Links are one of the most importantโ€ฆ
  5. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  6. Oct 9, 2026Post #4079
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’