My Backend Story
Introduction
So, it's a few days to submission deadline for my web application in fulfillment of the final project for my 12 months full-stack software engineering bootcamp by ALX Africa. My web app is yet to authenticate users who log in. This is supposed to be the first feature my team showcases in our demo, and I'm not yet sure how to implement this. I'm the backend guy of the team, building the backend API using Django Rest Framework (DRF). This is the first API I'm ever building. The rush of adrenaline, the anxiety, and the list of features yet to be fully functional.
This was my story a few weeks ago. One I can tell now, because I figured out how to implement the user authentication feature, and my team went on to complete the MVP for the project, create a demo, present our project, and graduate.
It's quite interesting that as a first project for my 8 weeks HNG internship program, I am sharing my experience to narrate how I approach challenges I have encountered on my backend SE journey.
Understanding the Problem
The problem with implementing the user authentication functionality for my API was that APIs are supposed to maintain a stateless feature. That is, a request to the API should contain all the necessary information to execute the request, and once executed, the information is forgotten. However, I had only worked with Django's session cookies, which do not satisfy statelessness.
On making some research on Google and with ChatGPT, I found out about tokens and how they differed from cookies in that a token could be configured to contain as data a user's email address, for example (which in the case of my project, was a unique identifier for every profile created).
The moment I was able to understand what the problem was, I knew that finding a solution was within reach.
Researching a Solution
On finding out how tokens were a solution to the problem of maintaining statelessness in my API, I made further research and came across JSON Web tokens (JWT), a compact, self-contained, secure form of token that was simple to implement and properly fit my use-case. A few keyboard clicks led me to a YouTube tutorial on how to implement JWT authentication in DRF using the simplejwt package. I made more in-depth research on the Simple JWT documentation, and I was good to go.
Testing the Solution
Where it is possible, I like to test a solution before incorporating it into the rest of my code. In my early days of programming where challenges were basically logic errors in my C code, I would create a separate main function simply to test the specific functionality which I was about to incorporate into the rest of my code. In this situation however, time was against me, so I simply installed the package into my environment, created the specified view function, connected it to the specified url route, and went on testing with a new user and a request from Postman. If I had come across any further errors, part of my debugging process would be testing this user authentication feature with a new minimalistic codebase. I was lucky though. Turns out simplejwt is that simple to implement.
Of course, I still had to write Unittests for my new feature.
Celebrate Your Little Wins
After I had pushed this code to my branch on GitHub and submitted a merge request, imagine the sense of pride with which I sent a message on the team's WhatsApp group informing the Frontend guys that the user authentication feature was ready on the API. I sipped the last of my malt drink, stretched my back, and stepped out to see the sun, making sure not to think of the next challenge for the time being until I returned to my system a few short minutes later.
Conclusion
With this post, I'm excited to begin my HNG internship journey. I'm optimistic about building real life solutions, and also connecting with the premium network that HNG Premium offers.
Thank you for walking with me through this exciting reminiscent journey. I hope you picked up a few tricks along the way.
Subscribe to my newsletter
Read articles from Daniel Herbert directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Daniel Herbert
Daniel Herbert
I am a veterinary doctor who left a job at a 5-star veterinary clinic in Lagos, Nigeria, to pursue a dream to become a software engineer. Going through vet school, and practicing for 5 years, I discovered gaps in the education and health sectors in Nigeria, which could be filled through simple tech solutions. My vision is to develop the necessary skills to be able to provide such solutions. I am currently training at ALX Africa to become a full-stack software engineer. Join me on this journey