'Not getting back any data using axios and tv maze api
I'm trying to get search data using the axios plugin from the TV Maze Api
<form method="POST" action="/results">
<input type="text" name="searchTerm" placeholder="Search for shows">
<input type="submit" value="Search">
</form>
I'm using a handlebar to post the information to my app.js
//Sets up results page
app.get("/results", mware.requireLogin, function(req, res) {
const simplifiedUser = {
username: req.user._doc.username,
isAdmin: req.user._doc.isAdmin
};
res.render("results", {
message: req.flash('info'),
user: simplifiedUser
});
});
// Process the form submission
app.post('/results', async function(req, res) {
const results = await showService.searchShows(req.body.searchTerm);
if(results && results.shows) {
res.render('results', {
results: results.shows,
searchTerm: req.body.searchTerm
});
} else {
res.render('error');
}
});
It then sends it off to retrieve that data but nothing is coming back. It keeps on skipping the data and goes straight ro rendering out the error message.
const showService = {
searchShows: async (term) => {
//searches for shows
// /search/shows?q=query
try {
const options = {
params: {
term,
}
};
const response = await axios.get(show_api + '/search/shows?q=', options);
if(response && response.data){
return response.data;
} else {
return ["did not work"];
}
//console.log(response);
} catch (error) {
console.error(error.response.data);
}
}
};
Any solution would help a lot thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
