Introduction
As a fun privacy experiment and to help my fellow learners, I decided to create an anonymous board where users can post messages without any login or sign-up requirements. This simple API allows anyone to create and read posts via unique links—perfect for beginners who want to get hands-on with FastAPI and SQLite. source code here
In this article, I'll walk you through how I built the API, the tools I used, and the lessons I learned along the way.
Tools and Libraries Used
For this project, I used the following technologies:
FastAPI: A modern web framework for building APIs quickly and efficiently.
SQLAlchemy: An ORM (Object-Relational Mapping) library to interact with the SQLite database.
Pydantic: For validating and parsing data in Python.
Uvicorn: A fast ASGI server to run the FastAPI app.
SQLite: A lightweight database for storing posts.
python-dotenv: For handling environment variables like database URLs and other configurations.
Features
Here’s what the current version of the API allows you to do:
Create anonymous posts: Anyone can post a message.
Unique link generation: Each post has a unique link for retrieval.
Retrieve posts: You can fetch the content of a post using its unique link.
No login required: The board is fully anonymous, so no need for user accounts or authentication.
How It Works
- Creating a Post: The POST /post endpoint allows you to submit content for a post. Once created, the API will return a unique link that you can use to view your post later.
Example request:
{
"content": "This is an anonymous message!"
}
Example response:
{
"content": "This is an anonymous message!",
"link": "127.0.0.1:8000/read/anonymous-dd3c"
}
- Reading a Post: The GET /read/{link} endpoint allows you to fetch the content of a post using the unique link provided during creation.
Example URL:
127.0.0.1:8000/read/anonymous-dd3c
Example response:
{
"content": "This is an anonymous message!"
}
Setting Up the Project
If you want to follow along and set up this project yourself, here’s how to do it:
Install Dependencies: You can install the necessary libraries by running the following command:
pip install fastapi sqlalchemy uvicorn python-dotenv
Run the Application: Start the FastAPI app with Uvicorn:
uvicorn main:app --reload
🧑💻 Future Plans
While the API is functional for now, I plan to add a frontend using HTML, Materialize CSS, and JS. The frontend will allow users to post and view anonymous messages more easily. I also plan to introduce an anonymous comment section where other users can share their thoughts, still without requiring any login.
💬 Feedback and Contributions
I’d love to hear any feedback or suggestions for improvement. This project is still in the early stages, and I’m always open to contributions. If you have any ideas, feel free to open an issue or submit a pull request! project github here