Skip to content

Latest commit

 

History

History
83 lines (54 loc) · 2.01 KB

File metadata and controls

83 lines (54 loc) · 2.01 KB

FastAPI and SurrealDB Backend Boilerplate

A simple starter kit for building RESTful APIs with FastAPI and SurrealDB

Features

  • Python FastAPI backend.
  • SurrealDB database.

Backend setup

2023-10-24.23-25-46.mp4
2023-10-24.23-22-55.mp4

To set up the backend, follow the outlined steps:

Setup Surreal Locally

  1. Ensure you have installed SurrealDB depending on the OS you are using (Linux, MacOS or Windows).

  2. Check that you have set up the database correctly. To do so, run:

surreal version
  1. 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.

Setup FastAPI Backend

Creating a virtual environment in /backend:

  1. Switch to the /backend directory
cd backend
  1. Create a Virtual Environment in the directory
python -m venv venv
  1. 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.

  1. Install the modules listed in the requirements.txt file:
(venv)$ pip3 install -r requirements.txt

Running the Server :

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.