Using FastAPI to perform the backend operations and establishing the connection between the UI and Database
- Python 3.7+
- MySQL database
VS code (1.89.1)
MySQL Workbench
Postman
python -m venv YOUR_FOLDER_NAME
source YOUR_FOLDER_NAME/bin/activate
cd YOUR_FOLDER_NAME\Scripts
activate
git clone https://github.com/WhiteboxHub/wbl-backend.git
cd wbl-backend
pip install fastapi
pip install uvicorn
pip install uvicorn[standard]
pip install mysql-connector-python
pip install python-jose
pip install passlib
- Install MySQL and login credentials
To run this project, you will need to add the following environment variables to your .env file
DB_HOST=00.000.00.00
DB_USER=UserName
DB_PASSWORD=Password
DB_NAME=DbName
DB_PORT=Port
SECRET_KEY=SecretKey
GET /api/items
Parameter | Type | Description |
---|---|---|
api_key |
string |
Required. Your API key |
GET /api/items/${id}
Parameter | Type | Description |
---|---|---|
id |
string |
Required. Id of item to fetch |
Takes two numbers and returns the sum.
https://github.com/WhiteboxHub/wbl-backend
- Light/dark mode toggle
- Live previews
- Fullscreen mode
- Cross platform
-
Start the FastAPI application:
bash uvicorn main:app --reload
-
Access the API documentation at http://127.0.0.1:8000/docs.
-
Endpoint: POST /users/
-
Request Body:
json { "username": "yourusername", "email": "[email protected]", "password": "yourpassword" }
-
Response:
json { "id": 1, "username": "yourusername", "email": "[email protected]" }
-
Endpoint: POST /token
-
Request Body: (as x-www-form-urlencoded)
text username=yourusername&password=yourpassword
-
Response:
json { "access_token": "your_access_token", "token_type": "bearer" }
-
Endpoint: GET /recordings
-
Headers:
text Authorization: Bearer your_access_token
-
Response: (Example)
json [ { "id": 1, "name": "Recording 1", "url": "http://example.com/recording1" } ]
- Create a new request in Postman.
- Set the request type to POST.
- Enter the URL: http://127.0.0.1:8000/token.
- Navigate to the Body tab and select x-www-form-urlencoded.
- Add the following key-value pairs:
- username: yourusername
- password: yourpassword
- Send the request.
- Copy the access_token from the response.
- Create a new request in Postman.
- Set the request type to GET.
- Enter the URL: http://127.0.0.1:8000/recordings.
- Navigate to the Authorization tab.
- Select Bearer Token from the Type dropdown.
- Paste the access_token into the Token field.
- Send the request.
- Inspect the response to ensure you can access the protected resource.
- Ensure that the SECRET_KEY in auth.py is kept secure and is not shared publicly.
- Verify that your MySQL database is running and accessible with the provided credentials.
- Check the FastAPI logs for any errors or warnings during requests.
- Make sure the token has not expired and is correctly formatted in the Authorization header.