This is a simple demonstration of a web application with a C backend and React frontend communicating via REST APIs.
- Backend: C HTTP server with REST endpoints
- Frontend: React with TypeScript
- Communication: HTTP REST APIs with JSON
- Build Tools: Make (C), Vite (React)
- ✅ C HTTP server with REST endpoints
- ✅ React frontend with TypeScript
- ✅ User management (GET/POST users)
- ✅ Health check endpoint
- ✅ Error handling and loading states
- ✅ Modern UI with responsive design
The C backend provides these REST endpoints:
GET /api/users- Get all usersPOST /api/users- Create a new userGET /api/health- Health checkGET /- Server info page
├── backend/
│ ├── server.c # C HTTP server
│ └── Makefile # Build configuration
├── src/
│ ├── components/ # React components
│ │ ├── UserList.tsx
│ │ ├── CreateUserForm.tsx
│ │ └── HealthStatus.tsx
│ ├── api.ts # API client
│ ├── App.tsx # Main React app
│ ├── main.tsx # React entry point
│ └── index.css # Styles
├── package.json # Node.js dependencies
├── vite.config.ts # Vite configuration
├── tsconfig.json # TypeScript configuration
└── index.html # HTML template
- C Compiler: GCC or Clang
- Node.js: Version 16 or higher
- npm: Package manager
npm installIn one terminal:
cd backend
make
./serverThe C server will start on port 8080.
In another terminal:
npm run devThe React app will start on port 3000.
Visit http://localhost:3000 in your browser.
-
Navigate to the backend directory:
cd backend -
Compile the C server:
make
-
Run the server:
./server
The server will display:
C REST API Server running on port 8080
Endpoints:
GET /api/users - Get all users
POST /api/users - Create a user
GET /api/health - Health check
GET / - Server info
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open
http://localhost:3000in your browser.
You can test the API endpoints directly:
curl http://localhost:8080/api/userscurl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Test User", "email": "test@example.com"}'curl http://localhost:8080/api/healthThe C server uses standard POSIX sockets to create an HTTP server that:
- Listens on port 8080
- Parses HTTP requests
- Routes requests to appropriate handlers
- Returns JSON responses
- Includes CORS headers for cross-origin requests
The React frontend:
- Uses Axios for HTTP requests
- Implements TypeScript for type safety
- Provides a modern UI with components
- Handles loading states and errors
- Communicates with the C backend via REST APIs
- React components make HTTP requests to
/api/*endpoints - Vite proxy forwards these requests to
localhost:8080 - C server processes requests and returns JSON responses
- React components update the UI based on responses
- The C server includes basic CORS headers for development
- Error handling is implemented on both frontend and backend
- The frontend includes loading states and user feedback
- TypeScript provides type safety for API interactions
- Port already in use: Make sure no other service is using port 8080
- Compilation errors: Ensure you have GCC or Clang installed
- Permission denied: Make sure the server executable has proper permissions
- Cannot connect to backend: Ensure the C server is running on port 8080
- Build errors: Run
npm installto ensure all dependencies are installed - TypeScript errors: Check that all types are properly defined
This demo can be extended with:
- Database integration (SQLite, PostgreSQL)
- Authentication and authorization
- More CRUD operations (PUT, DELETE)
- Real-time updates with WebSockets
- Docker containerization
- Production deployment configuration
This project is for educational purposes and demonstrates REST API integration between C and React.