This is a FastAPI backend that provides API endpoints for the Berry React Admin Template frontend.
- GET /api/hello - Returns a greeting message
- POST /api/hello - Accepts a message and echoes it back
- GET /api/users - Returns a list of sample users
- POST /api/users - Creates a new user and adds it to the in-memory list
- CORS support for
http://localhost:3000(React frontend)
- Python 3.8 or higher
- pip (Python package installer)
- Navigate to the backend directory:
cd backend- Create a virtual environment (recommended):
python3 -m venv venv-
Activate the virtual environment:
- On Linux/Mac:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On Linux/Mac:
-
Install the dependencies:
pip install -r requirements.txtStart the FastAPI server using uvicorn:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The server will start at http://localhost:8000
Returns a greeting message.
Response:
{
"message": "Hello from FastAPI!"
}Example:
curl http://localhost:8000/api/helloAccepts a message and echoes it back.
Request Body:
{
"message": "Your custom message"
}Response:
{
"message": "Your custom message"
}Example:
curl -X POST http://localhost:8000/api/hello \
-H "Content-Type: application/json" \
-d '{"message": "Hello from the client!"}'Returns a list of sample users.
Response:
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]Example:
curl http://localhost:8000/api/usersCreates a new user and adds it to the in-memory list.
Request Body:
{
"name": "John Doe"
}Response:
{
"id": 3,
"name": "John Doe"
}Example:
curl -X POST http://localhost:8000/api/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe"}'FastAPI automatically generates interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The --reload flag enables auto-reload on code changes, which is useful during development.
The backend is configured to accept requests from the React frontend running on http://localhost:3000. Make sure both the backend and frontend are running simultaneously for proper integration.
To start the React frontend, navigate to the vite directory and run:
npm install # or yarn install
npm start # or yarn start