How to get response from an API after sending a request in node js

So I’m trying to integrate this API I just got into my application, but the API have no documentation so am finding it had to do so. After sending a request to the API, it does not send a request back and its leaving my site

res.redirect(
    "https://app.nuban.com.ng/api/NUBAN-KWXJZXIZ429?bank_code=032&acc_no=0090921262"
  );

After redirecting, I want to get back a response from the API but its shows the information in another tab this is the response I want but it is no longer on my site

Is there a way I can get this response to store in a variable, or am I just using the API wrongly?

4 thoughts on “How to get response from an API after sending a request in node js”

  1. If you want to return from your server request handler the results of calling that API, then you have to code this differently in your request handler. You need to actually call the API, parse the JSON it returns to get the results and use that as the result you send back from your request handler. I like to use the got() library for making external http requests, but there are many other choices here.

    const got = require('got');
    
    app.get("/api/some_api_call", async (req, res) => {
        try {
            const url = "https://app.nuban.com.ng/api/NUBAN-KWXJZXIZ429?bank_code=032&acc_no=0090921262";
            let data = await got(url).json();
            res.send(data);
        } catch(e) {
            console.log(e);
            res.sendStatus(500);
        }
    });
    
    Reply

Leave a Comment