A simple starter kit for building RESTful APIs with FastAPI and SurrealDB
- Python FastAPI backend.
- SurrealDB database.
2023-10-24.23-25-46.mp4
2023-10-24.23-22-55.mp4
To set up the backend, follow the outlined steps:
-
Ensure you have installed SurrealDB depending on the OS you are using (Linux, MacOS or Windows).
-
Check that you have set up the database correctly. To do so, run:
surreal version
- Start the SurrealDB database server using the command:
On Windows
surreal.exe start
On MacOS
surreal start
This will start an in-memory database server that will lose data when the server is restarted. However, you will have quicker data access times than when you read and write from disk.
- Switch to the
/backend
directory
cd backend
- Create a Virtual Environment in the directory
python -m venv venv
- Activate the Virtual Environment
- if you are using
Git Bash
:
source venv/Scripts/activate
- Else :
source venv/bin/activate
In case of any other issue in Activating the Virtual Environment, refer to this StackOverFlow Answer.
- Install the modules listed in the
requirements.txt
file:
(venv)$ pip3 install -r requirements.txt
uvicorn main:app --port 80 --reload
The starter listens on port 80 on address localhost:80. Make sure to add the Port flag as 80
for the FastAPI backend. By default uvicorn loads on port :8000
.