Efficient, Effective, And Clean Coding Using Fetch Request

Brayarn Oduor
3 min readSep 4, 2022

One of the most challenging aspects of coding is making sure that your program is efficient, effective, and clean. This can be a difficult task, especially when working with large projects. In my experience, one of the best ways to ensure that your code is up to par is to have a clean code. One way of ensuring this is using the DRY method and making fetch requests to an API to mock a server. The DRY method simply means “don’t repeat yourself”.

MovieIt project hero

I was recently working on my Moringa School–Flatiron Phase 1 project that required me to retrieve data from a server and then display it on a webpage. I knew that I could use fetch requests to accomplish this task. However, this was my first time working with fetch requests, and I learned a lot in the process. I also wanted to challenge myself by creating my own API– Oh boy! Here are some of the challenges I faced and the lessons I learned.

Fetch requests are a great way to retrieve data from a server. However, they can also be used to POST data to a server. This makes them incredibly versatile and powerful tools for coders. One of the things I learned is that it’s important to pay attention to the details when working with code. Even small details can make a big difference in whether your code works correctly.

From the lectures and labs during the phase 1 studies, I managed to create my own JSON file to mock an API. Reusing functions also ensures that the code is short and clean. The real test was making the API available publicly. I spent two days ravaging the internet, searching, roiled in the confusion about whether this was a mistake or not. You can imagine the excitement when I finally hacked it. Take it this way, you spend an entire week trying to find a bug in 1001 lines of code, and when you’re almost giving up — boom! Just a simple code termination! Well, it’s a frustration for overlooking a simple semicolon in your code, and excitement for finally solving the problem.

Another challenge I faced was figuring out how to handle the data that was returned from the API. The data came back in a format that I wasn’t familiar with, and it took some time to figure out how to parse it correctly. In the end, I was able to use some built-in methods to convert the data into a format that I could work with. This was another lesson I learned: sometimes it’s necessary to dig deeper into the documentation to find the information you need.

Overall, I’m glad I took on this project, even though it was challenging at times. It was a good learning experience, and I now have a better understanding of how fetch requests work. If you’re facing similar challenges, don’t give up! Keep pushing through, and you’ll eventually get it figured out.

--

--