Leslie Mathys

09: Facing A Fear

This post is part of my Dailies collection. You can see more here

In my last piece I discussed following my curiosity more when it comes to coding. Well, I decided to start walking my talk. My first port of call was to actually take the advice I've heard countless times before: experiment with something small and self contained.

So I did.

WebDev™ industry love using jargon, and I think part of it is a gatekeeping mechanism. Anyway, I decided to face my (admittedly irrational) fear of... APIs and JSON. For some reason these phrases have always had a sort of mystique to me, almost as if they were out of my reach. Whenever I heard 'API', my mind would immediately start thinking of 'header', 'keys', 'parameters', 'queries' etc. This would actually evoke an anxious response. So I just stayed away from it.

So I decided to find a football (soccer) related API that I could just query with Javascript. I found one, and got to work. Looking through the docs, I was able to see how an example call could be structured. Digging through things a bit more, I realised that Javascript has the fetch() API. Reading through those docs I got a bit more of an understanding how it needs to be structured.

Still unsure where to actually start, I copied and pasted the example call and tinkered from there. It worked. But I didn't know why it worked. That's when I tried for my pal Claude and explained what I was doing. At first, my instructions were to explain what the code is doing step by step. By doing that, it raised the concept of promises and how they work. Eventually, I was using Claude as a Socratic tutor, to teach me how to traverse an API response using Object.keys() and how this can be used to investigate the structure of a response. It kept asking me more questions, and I eventually came to the realisation that Object.keys() doesn't work when you want return actual data. If I wanted that, I just needed to use console.log and it'd give me what I needed.

In about an hour I was able to get a little more comfortable with APIs and JSON by doing something bite-sized.

My next challenge will be to tie this into some sort of user interface.

Stay tuned.


This post was last edited 3 months, 3 weeks ago.

#dailies