This FastAPI application is a sample implementation with integrated database migrations using Alembic, authentication via Hanko, and managed dependencies with Poetry. Below is a brief README to help you understand and manage this application.
git clone https://github.com/Akachi-Anabanti/fastapi-hanko
cd backend
Make sure you have Poetry installed. If not, you can install it following the instructions here: Poetry Installation.
Use Poetry to install the project's dependencies:
poetry install
This application uses Alembic for database migrations. To set up the database, you need to create the database and apply migrations:
# Create the database (you may need to configure your database connection in app/config.py)
poetry run alembic upgrade head
The application uses Hanko for authentication. Configure your Hanko API credentials in app/config.py
:
HANKO_API_URL=https://a8ff***m89f8s***904d7.io
visit Hanko Cloud to obtain your api url
You can start the FastAPI application using Poetry:
poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
The application will be accessible at http://localhost:8000.
-
Retrieve Items - GET
/item/
Retrieve a list of items. The
limit
andskip
parameters can be used for pagination. Users with superuser privileges can access all items, while others can only access their own items. -
Create Item - POST
/item/
Create a new item. This endpoint requires authentication. The item will be associated with the authenticated user.
-
Update Item - PUT
/item/{id}
Update an item by providing its
id
. Only the owner of the item can update it. If the item is not found or the user doesn't have sufficient permissions, an error will be raised. -
Get Item by ID - GET
/item/{id}
Retrieve an item by its
id
. Users can only access items they own. If the item is not found or the user doesn't have sufficient permissions, an error will be raised. -
Delete Item - DELETE
/item/{id}
Delete an item by providing its
id
. Only the owner of the item can delete it. If the item is not found or the user doesn't have sufficient permissions, an error will be raised.
This application uses Hanko for authentication. Make sure to configure Hanko API credentials in app/config.py
as mentioned earlier.
The application uses Alembic for managing database migrations. You can create and apply migrations as needed with Poetry:
# Create a new migration
poetry run alembic revision --autogenerate -m "Your migration message"
# Apply pending migrations
poetry run alembic upgrade head
if you added new models and schemas run
poetry run alembic revision --autogenerate -m "revision message"
to generate a new revision and then apply the migration as above
Feel free to contribute to this project by submitting pull requests or reporting issues on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.