Table of contents
No headings in the article.
In this new series that I am going to start and hopefully continue, I ask ChatGPT to give me problem statements on topics I want to learn and I try to do the same. The idea is to ask AI to create problems instead of solving them. Although a little bit of research will result in a problem statement, I want to learn how to approach take-home assignments that are given by recruiters, with Chat GPT I can generate detailed problem statements and will not have a choice to pick whatever I want.
I was trying to learn fastapi as I am interested in backend development, though the problem statement it generated was a pretty simple one, it was a nice experience to work on, and I will be working on more such projects in future. Now onto the actual project and my interaction with ChatGPT.
So not only it gave me two different problems to solve, it even gave me a few free hosting options, I ended up using Render for deployment which is another free platform for hosting different kinds of services.
The development process started with me reading a few articles and watching videos about the fastapi and doing CRUD operations with it. One great thing which I liked was the swagger UI which self-documents the operations you define and everything can be run and tested then and there which makes the development, testing as well and presentation of the app very easy.
Though this is a very simple project and all parts of the code can be defined in a single file, I wanted it to be in structured way so that when I am working at scale it will be easier, so there are 4 different folders which include config which has the configuration information for the MongoDB connection, have to use Mongo as the database, the second folder is the schema which defines the schema needed for this case, third is the model and finally the most important one, routes which define all the endpoints of the application.
This is the first place where I ran into a problem as I had added even the ID of the task in the Base model which actually should not be there as we are not supposed to change the ID, so while running the PUT operation it was causing issues, figured that out soon and fixed it. There are multiple operations which we will need for deleting all, getting a specific task, and updating specific values which are delete_many(), find_one(), and update_one() respectively. The complete implementation is available on my GitHub repo here: https://github.com/SammithSB/todo-list-fastapi
Finally, as part of fake DevOps, I added a linting mechanism for the code using Black and GitHub workflows. To deploy the code on render I needed to dockerise the code, I have below to average level of experience with that but I was too tired at this point and just wanted to get over with it, this caused a huge downfall as I was not fully into it and kept doing whatever I saw after googling without giving even slight thought about what was written. I thought the machines beat me.
After repeating this nonsense for a while I reached my senses and started reading suggestions properly and ended up fixing the issue quickly. The issue was I was not copying all the required files to the working directory correctly even thought I was doing it right, it sounds super stupid but it is what it is, and that's how I beat the machine and dockerised and deployed the app successfully.
You guys can check it out at this URL: https://todo-list-api-it9x.onrender.com/docs
If you have any suggestions or additions you want to add to this repo, feel free to do it, one thing I do want to do is add unit test cases for this, if anyone is interested in contributing to this, DO IT.
Ashte, tata bye bye machas. Will come back with another ChatGPT assigned assignment, if you have any ideas, give off, will definitely do.
References:
https://www.youtube.com/watch?v=G7hZlOLhhMY
https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/
https://testdriven.io/blog/fastapi-mongo/
https://betterprogramming.pub/dockerizing-your-fastapi-project-d8bb13ad6335