DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: