Using this example
Installation
Clone this repository and install the dependencies. This project uses Poetry for dependency management which should be installed on your system first.
Install the dependencies:
1 |
|
Then switch to the virtual environment:
1 |
|
Usage
Run the server using Uvicorn
:
1 |
|
Note
You can also run the server by just executing the main.py
file:
1 |
|
or using the included POE
alias:
1 |
|
Then open your browser at http://localhost:8000.
There is only one endpoint available: /users
. It returns a list of all users for a GET
request and creates a new user for a POST
request.
Local Postgres server using Docker
This example uses PostgreSQL as the database. If you dont have a local PostgreSQL database running, you can start one with Docker using the following command:
1 2 3 4 5 6 7 8 |
|
This will run a PostgreSQL database in a Docker container in the background. When you are finished and want to stop the database, run:
1 |
|
If needed, you can connect to the database managment by :
1 |
|
This will allow you to edit or delete the database or records.
Use SQLite instead of PostgreSQL
For testing purposes, you can also use SQLite instead of PostgreSQL. To do so, open the db.py
file and comment out the PostgreSQL database in the DATABASE_URL
environment variable and uncomment the SQLite database.
1 2 |
|