What could be causing this axios.get request to fail?

I am currently enrolled in Colt Steele's Web Developer bootcamp and facing a challenge...

In the tutorial, we are using axios as 'request' has been discontinued, so I am trying to follow along with this change.

My goal is to set up a Get route for a '/results' page, where I can retrieve information from the OMDB Movie Database and display the JSON file when I visit the URL.

Despite hours of searching, I have not been able to find a solution. Here is my code:

const express = require('express');
const app = express();
const axios = require('axios').default;

app.listen(3000, () => {
    console.log('Im listening');
});

app.get('/results', (req, res) => {
    axios.get('http://www.omdbapi.com/?t=california&apikey=thewdb')
        .then((response) => {
            res.send(response);
        }).catch((err) => {
            console.log('This isnt right');
        })

});

I also have express installed correctly. When I use console.log(response) like this:

axios.get('http://www.omdbapi.com/?t=california&apikey=thewdb')
        .then((response) => {
            console.log(response);
        }).catch((err) => {
            console.log('This isnt right');
        })

The API JSON is displayed in my console, which leads me to believe there might be an issue with using res.send(response) in the promise.

Any assistance would be highly appreciated. Sorry if I missed any important details, I'm still learning...

Answer №1

If you want to access the response data from an OMDb request, you can use the data property:

app.get('/', function (req, res, next) {
    axios.get('http://www.omdbapi.com/?t=california&apikey=thewdb')
        .then(result => res.send(result.data))
        .catch(err => res.send(err));
});

To learn more about this, check out Axios's Response Schema documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is NoSQL supported by the MySQL Community Edition?

I have decided to dive into learning and developing a Node.js application with SQL. I am aware that the MySQL Enterprise Edition offers support for NoSQL, but I'm curious if the community edition also supports NoSQL or if I need to invest in the enter ...

Could anyone lend a hand in ensuring that my AJAX call successfully processes the parameters?

When attempting to retrieve specific data from my database using AJAX, I encountered an issue where the call was successful when made through Postman or directly in the browser, but failed when initiated from my client. It seemed to work intermittently, re ...

Manipulating data in a C# application using JSON

I am currently developing a desktop application for managing requests and responses. So far, I have successfully implemented GET requests, but now I need assistance in understanding how to handle JSON requests and responses. Once I can parse the JSON dat ...

Transforming a Java object containing embedded Java objects into JSON format

Is there an easy way to serialize a Java class with nested array of Java classes into JSON format? For example, I would like to convert an instance of the below class into JSON: public class Students { private final String studentId; private final ...

When I switch to a different navigation system, the css class gets removed

Let me clarify what I am looking for: Upon entering the index.php page, LINK_1 button is active. When I switch to LINK_2, it becomes active. I have only one index.php page where I include parts of external pages using PHP. Page_1 https://i.sstatic.net/Yv ...

Error: Syntax mishap detected - Oh dear

Recently, I've been developing a small slideshow / public display for a client using the HTML5 Rock's Slideshow code. Everything was going smoothly until I encountered a DOM Exception 12 - an error related to CSS selectors. Strangely, I couldn&ap ...

Using express-boom for badRequest in your application is a simple and effective

Recently, I've started working with node+express and decided to incorporate the express-boom module into my project. While browsing through the official Express website, I came across the following snippet that caught my attention. However, I'm u ...

Navigate through collections of objects containing sub-collections of more objects

The backend is sending an object that contains an array of objects, which in turn contain more arrays of objects, creating a tree structure. I need a way to navigate between these objects by following the array and then back again. What would be the most ...

When a function inside React uses this.props, it won't trigger the corresponding function

I am currently developing a Checklist using React and MaterialUI that consists of two components. One component is responsible for managing the data, while the other component allows for editing the data. However, I have encountered an issue where the func ...

Tips for implementing multi-language URL routing in a Node.js application

I am seeking guidance on how to handle routing for multi-language URLs in Node.js, Currently, I have the following routes set up where each language generates specific routes as shown below. However, with more than 5 languages, efficiency is becoming a co ...

Ways to troubleshoot and verify values in PHP that are sent through AJAX

In my jQuery function, I am using AJAX to send values to a PHP file: $.ajax({ //make ajax request to cart_process.php url: "cart_process.php", type: "POST", dataType: "json", //expect json value from server data: { quantity: iqty, ...

The generated hook in vuejs is throwing an error stating that window/localstorage is not defined

My goal is to save an authenticated user to local storage and then load them into Vuex on the next page load. created () { let user = window.localStorage.getItem('user') if(user) { this.setUser(JSON.parse(user)) } } I initia ...

Expo: A guide on integrating expo code into an existing Android project

I'm looking to enhance my Android app (which is built in standard Java) by allowing users to create their own 3D models. To achieve this, I want to incorporate a 3D viewer within the app so that users can view and interact with their creations. My pl ...

Is there a way to retrieve the current map center coordinates using the getCenter function in @react-google-maps/api?

I am currently working with the GoogleMap component provided by @react-google-maps/api, but I am struggling to figure out how to obtain the latitude and longitude coordinates of the map's center after it has been moved. After some research, I came ac ...

Having trouble executing multiple file uploads with node.js resulting in an ERR_EMPTY_RESPONSE?

Currently, I am attempting to upload multiple files on FTP using node.js. Everything seems to be going smoothly as the files are successfully uploaded to the server location. However, after some time passes, I do not receive a success message. Instead, I e ...

How can you avoid Ajax calls from failing due to frequent requests?

Currently, I am utilizing ajax to retrieve some data. However, I have encountered an issue where the ajax request is triggered by hovering over a button, which could potentially result in multiple requests being sent and overwhelming the server, leading to ...

Parsing JSON data using multilevel iteration in JavaScript is a complex yet

{ "id":0, "item":[ { "id":"0-", "text":"BlueWing", "userdata":[ { "name":"cid", "content":"10377" } ], "item":[ { "id" ...

Utilize Protractor Selenium to extract content from a popup window

Having trouble capturing the text from a popup using Protractor with getText? The HTML structure can be found here. This popup only appears for a few seconds before disappearing. Can anyone assist me in retrieving the text from this popup? To retrieve the ...

What is the best way to interpret JSON in Swift if it contains an array with two levels of nested elements?

Let's take a look at the following JSON structure: [ { "data": { "children": [ { "name": "Ralph" }, { "name": "Woofer" } ] } }, { "data": { ...

Encountering a 'type error' stating that $(...).modal is not a valid function

While working on a REACT project, I encountered an issue while trying to create and edit a function for updating notes by users using bootstrap modals. The error message that appeared is: Uncaught (in promise) TypeError: jquery__WEBPACK_IMPORTED_MODULE_1__ ...