Skip to content
Open

post #146

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
367c89d
Initial plan
Copilot Oct 7, 2025
315ab39
Add FastAPI backend with /api/hello and /api/users endpoints
Copilot Oct 7, 2025
a453225
Merge pull request #1 from leandrorubysp/copilot/add-fastapi-backend-…
leandrorubysp Oct 7, 2025
d069c61
Primeira integração FastAPI com React Template e adição do docker com…
leandrorubysp Oct 7, 2025
d6fc63b
Remover remix para não confudir
leandrorubysp Oct 7, 2025
c09656e
Initial plan
Copilot Oct 7, 2025
bd161a4
Initial plan
Copilot Oct 7, 2025
c0fcb34
Add POST endpoints to /api/hello and /api/users with documentation
Copilot Oct 7, 2025
5d8c155
Add FastAPI Demo POST page with form components
Copilot Oct 7, 2025
000611e
Initial plan
Copilot Oct 7, 2025
a0f8be0
Merge pull request #4 from leandrorubysp/copilot/integrate-sqlite-wit…
leandrorubysp Oct 7, 2025
a08e483
Merge pull request #3 from leandrorubysp/copilot/add-fastapi-demo-page
leandrorubysp Oct 7, 2025
1a14d92
Merge branch 'main' into copilot/add-post-endpoints-hello-users
leandrorubysp Oct 7, 2025
7cf105f
Merge pull request #2 from leandrorubysp/copilot/add-post-endpoints-h…
leandrorubysp Oct 7, 2025
7dcca79
Initial plan
Copilot Oct 7, 2025
fd4f256
Merge pull request #5 from leandrorubysp/copilot/refactor-fastapi-use…
leandrorubysp Oct 7, 2025
584469c
Initial plan
Copilot Oct 7, 2025
3353f40
Merge pull request #6 from leandrorubysp/copilot/update-hello-endpoin…
leandrorubysp Oct 7, 2025
cc60245
Initial plan
Copilot Oct 7, 2025
6489559
Merge pull request #7 from leandrorubysp/copilot/update-hello-message…
leandrorubysp Oct 7, 2025
4d3f491
Initial plan
Copilot Oct 7, 2025
30bf41f
Merge pull request #8 from leandrorubysp/copilot/add-fastapi-list-dem…
leandrorubysp Oct 7, 2025
586d1c5
Update requirements.txt with new dependencies
leandrorubysp Oct 7, 2025
2d7ae11
Alguns examplos de CRUD com FastAPI e Reac
leandrorubysp Oct 8, 2025
28f7d7b
Correções para tudo funcionar
leandrorubysp Oct 8, 2025
8b40f3c
Cadastro de usuário
leandrorubysp Oct 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
env/
ENV/
.venv

# FastAPI
.pytest_cache/
.coverage
htmlcov/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db
12 changes: 12 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Backend Dockerfile for FastAPI
FROM python:3.11

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY app ./app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
160 changes: 160 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# FastAPI Backend for Berry React Admin Template

This is a FastAPI backend that provides API endpoints for the Berry React Admin Template frontend.

## Features

- **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)

## Prerequisites

- Python 3.8 or higher
- pip (Python package installer)

## Installation

1. Navigate to the backend directory:
```bash
cd backend
```

2. Create a virtual environment (recommended):
```bash
python3 -m venv venv
```

3. Activate the virtual environment:
- On Linux/Mac:
```bash
source venv/bin/activate
```
- On Windows:
```bash
venv\Scripts\activate
```

4. Install the dependencies:
```bash
pip install -r requirements.txt
```

## Running the Backend

Start the FastAPI server using uvicorn:

```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```

The server will start at `http://localhost:8000`

## API Endpoints

### GET /api/hello

Returns a greeting message.

**Response:**
```json
{
"message": "Hello from FastAPI!"
}
```

**Example:**
```bash
curl http://localhost:8000/api/hello
```

### POST /api/hello

Accepts a message and echoes it back.

**Request Body:**
```json
{
"message": "Your custom message"
}
```

**Response:**
```json
{
"message": "Your custom message"
}
```

**Example:**
```bash
curl -X POST http://localhost:8000/api/hello \
-H "Content-Type: application/json" \
-d '{"message": "Hello from the client!"}'
```

### GET /api/users

Returns a list of sample users.

**Response:**
```json
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
```

**Example:**
```bash
curl http://localhost:8000/api/users
```

### POST /api/users

Creates a new user and adds it to the in-memory list.

**Request Body:**
```json
{
"name": "John Doe"
}
```

**Response:**
```json
{
"id": 3,
"name": "John Doe"
}
```

**Example:**
```bash
curl -X POST http://localhost:8000/api/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe"}'
```

## Interactive API Documentation

FastAPI automatically generates interactive API documentation:

- **Swagger UI**: http://localhost:8000/docs
- **ReDoc**: http://localhost:8000/redoc

## Development

The `--reload` flag enables auto-reload on code changes, which is useful during development.

## Integration with React Frontend

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:
```bash
npm install # or yarn install
npm start # or yarn start
```
1 change: 1 addition & 0 deletions backend/app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JWT_SECRET_KEY=jc8tcjEaszesrR7xzVdb30y6PCEbKzSBfuFa4k0y-7l37BzXufYDmjO-D94cKNI3TIuFYONOFUrwBMNxYuZkcw
18 changes: 18 additions & 0 deletions backend/app/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base

SQLALCHEMY_DATABASE_URL = "sqlite:///./app.db"

engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
Loading