Phase-1 Project: CAP KEEPS
Tags: javascript, webdev, beginners, api
Published: 2022-02-24 05:26:30

"_Find, save, and easily create photo captions in minutes. No cap._"

As a student at Flatiron School, for my Phase-1 project I created a front-end web application that allows music and social media enthusiast to save Instagram captions for future posts using either song lyrics returned from a public API or manually entered to create custom captions of their own. 


### **BACKSTORY**
You've picked the perfect post-worthy picture, now you're left with the question "_What should my caption be?_" This is a question I hear way too often amongst my group of friends. With a [quick Google search](https://www.google.com/search?q=instagram+captions&rlz=1C5CHFA_enUS978US978&oq=instagram+captions&aqs=chrome..69i57j0i512j0i433i512j0i131i433i512j0i512l2j0i433i512j0i512l3.3543j0j9&sourceid=chrome&ie=UTF-8), you can see there are _thousands_ of websites catered to Instagram captions alone and it's no secret that song lyrics make some of the **best** captions. This tool I created removes the extra decision making and researching before your next Instagram post. You can access your personal vault of save captions with ease.

### **HOW IT WORKS**
When searching for captions using CAP KEEPS, users can input a string of words in the front-end web form. CAP KEEPS takes that string and generates a custom URL that is used in a Fetch method directly to [Genius Lyrics](https://genius.com/) API, a public lyric database.

![GIF of CAP KEEPS expected behaviors](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4sl3i6lw52ic88hp1h0.gif)

The fetch request returns the 5 top lyric results in an array. The tools then maps through that array and creates an object using the returned lyric snippet, song, artist, and artist image which are then displayed in an unordered list to the user.

![Preview of captions returned from search results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xq7dneh4rskze2qxap6.png)

As a user, you have that option to '_Keep_' or '_Unkeep_' captions returned in the search results. Kept captions are pushed to the database (and when you '_Unkeep_' a caption, it's removed from the database).
 
When you click on "My Captions", similar behavior happens when search results are returned. For each caption stored in the database, it creates an HTML element using the object data and appends it to an unordered list. Here, users can manage their saved captions which includes favoriting ('_Like_' heart), copying lyrics to the clipboard, or deleting the caption (which uses a method to remove the HTML element and delete the caption from database).

![Users can interact with saved captions under 'My Captions'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8g4dqg9y6prwumt6d0xh.png)

### **OVERCOMING OBSTACLES**
At first attempt, fetching data from a public API was a little intimidating. I used [Rapid API](https://rapidapi.com/) for the first time, a public API hub that was very beginner-friendly. Rapid API allows you to test endpoints and preview the type of response you would receive from the fetch request. This gave me the opportunity to experiment and get an idea for the method I would I need to create for mapping through this response.

![Rapid API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6qwxkc2h5j6147a37lw.png)

In order to generate the URL for the fetch request to Genius API, I had to create a special method that takes the string provided in the input field and replaced spaces with '%20' (thank you late night Google searches!). An example of the code I mimicked can be found [here](https://www.codespeedy.com/how-to-replace-space-with-20-in-javascript/).

### **TAKEAWAYS**
1. **It doesn't have to look nice right away, just get it to work! (MVP and Pseudo**)

> I've always been big on presentation but during this process, the MVP technique was my savior. Step by step, I would write out exactly what I was trying to do, when I wanted this to happen in my code. As my code grew longer and longer, going back to the MVP technique really helped me get my thoughts down and stay organized. There's always time to go back and clean things up. 

2. **Set boundaries and know when to ask for help.**

> I love programming, but almost _too_ much sometimes. During this project, when I was deep in a solve, I found myself spending hours diving through resources to find a solution. I learned how important it is to stop and know when to ask for help or get a second opinion (no matter how much fun you're having trying to find the answer on your own). Having my MVP written out made it even easier to ask questions since I knew exactly what I was trying to do. Time management and asking questions is key for productivity. 

3. **Methods save so much time.**

> Working on this project really highlighted how repetitive code can be when you're writing it. I learned there's almost always a flexible method you can create to handle almost anything for your app. I'm excited to continuing building on these skills to have clean code.

If you're interested in viewing CAP KEEPS, checkout my repo: https://github.com/breonwhite/phase-1-project-cap-keeps
Youtube: https://youtu.be/OSLuZkXDnXQ