[go: up one dir, main page]

DEV Community

Cover image for API and Database Playing Together
Jackson Reeves
Jackson Reeves

Posted on

API and Database Playing Together

I was in Promises Hell for about three days until I finally came up with this code. The problem: I needed to query my local database, then use the result from that query to make an API call, then render the results of both the database query and the API call on an EJS views page. This did not go as smoothly as I would have liked. The main hurdle was that my original code required making multiple API calls before moving on to the render stage, which landed me in Promises Hell. My solution was to parse some info from my database query to create a single string that I could feed into my API call, so I only needed to make one call instead of multiple (potentially hundreds) of calls each time. Then I was able to neatly package it all up and send it to my rated EJS views page. Oh, complicated routes, you certainly can be fun.

Top comments (0)