Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.41 KB

File metadata and controls

74 lines (55 loc) · 1.41 KB

FastAPI Backend

Crud Application

This is to serve as my very first experience using FastAPI, and a reference project for the future.

Documentation

All the documentation of the project can be found in the /docs directory.

Implementation

Prerequisites

  • Python installed
  • MySQL installed and running
  • A MySQL database created and ready

Setup

1. Clone the repository

git clone <your-repo-url>
cd <your-repo-name>

2. Create and activate the virtual environment inside the Project's Folder

# Create
python -m venv .venv

# Activate on Mac/Linux
source .venv/bin/activate

# Activate on Windows
.venv\Scripts\activate

3. Install the required Packages

pip install -r requirements.txt

4. Set up the database

Run the following SQL in your MySQL client:

CREATE DATABASE your_database_name;

USE your_database_name;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    familyName VARCHAR(100) NOT NULL,
    age INT NOT NULL
);

5. Configure environment variables

Create a .env file at the root of the project:

DB_HOST=localhost
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=your_database_name

6. Launch the server

uvicorn app.main:app --reload
  • The API will be available at http://localhost:8000
  • API documentation available at http://localhost:8000/docs