This project is a RESTful mini blog written in FastAPI with user registration and authorization. Interaction with database is done via SQLAlchemy, migrations via Alembic
- User control:
- Registration and authorization using cookies.
- Posts operations:
- Post viewing:
- Recieving the list of all "published" posts.
- Viewing the specific post.
- Filtering posts by author or tag.
- Paging:
- Posts list is devided into pages.
- Specific page can be requested via API.
- Page size can be controled via API.
- Creation:
- Registered users can make new posts.
- Post can be saved as "draft".
- New post consists of a title, a short description, a body and optional tags.
- Deletion:
- Authors can permanently remove their posts.
- Status changing:
- Post's author is able to change the post's status. Available options are "published" and "draft".
- Only post's author can see his drafts through API.
- Posts with status "published" are seen by every user, including non-registered ones.
- Tags control:
- Posts may have multiple tags.
- If a user create a post with unknown tag, this tag is automatically created and saved in database, so everyone can filter posts by it.
- Post viewing:
- Logging:
loguruis used as a logging system. Though it could be done via built-in python logging,loguruhas much more simple usage when extending logging logic.
- Module architecture:
- The code is divided on multiple modules(e.g. authentication, main API, pages viewing), so it is easy to scale the app .
- Framework: FastAPI
- Web Server: Uvicorn
- ORM: asynchronous SQLAlchemy
- DB engine: SQLite (can be easily swapped to any, thanks to ORM)
- Migrations: Alembic
- Frontend: Jinja2 (template engine), HTML, CSS, JS
- Dependency management: poetry
- Clone the repo:
git clone https://github.com/bivafra/fastapiblog.git cd fastapiblog - Install dependencies:
poetry install
Note: migrations are already applied. If you want to do them manually, then consider alembic.ini and app/migration/env.py files for configure details. Then remove alembic.ini, app/migration and run:
cd app
alembic init -t async migration
alembic revision --autogenerate -m "Initial migration"
alembic upgrade headpoetry run uvicorn app.main:app --reload
- Visit main page at http://127.0.0.1:8000.
- Interactive API documentation is autogenerated with SwaggerUI and available at http://127.0.0.1:8000/api. That means you will see nice page with all available API endpoints. Also, for now, this is the only way to interact with API for registration/authentication and posts creation.
- Frontend interface for user registration/authorization, posts creation.
- Search by post's title.
- Posts commenting.
- Adding users roles(administrator, redactor, etc.)
- Switching to more common DB(e.g. postgresql)





