Reputation:
I am trying to retrieve data using the OMDB API & keep being presented with 'internel server error' despite my data request: res.send(results["search"][0]) (Please note that I am using the goorm IDE)
var express = require("express");
var app = express();
var request = require("request");
app.get("/results", function(req, res){
request("http://www.omdbapi.com/?s=california&apikey=thewdb", function(error, response, body){
if(!error && response.statusCode == 200) {
var results = JSON.parse(body);
res.send(results["search"][0]);
}
});
});
app.listen(3000, function(){
console.log("SERVER IS RUNNING");
});
Upvotes: 0
Views: 92
Reputation: 1141
Can you try it?
app.get("/results", (req, res) => {
request("http://www.omdbapi.com/?s=california&apikey=thewdb", (error, response, body) => {
(!error && response.statusCode == 200) ?
res.send(JSON.parse(body).Search[0])
:
res.send({ err: error });
});
});
Upvotes: 0
Reputation: 4643
Object properties in javascript are strings and they are case sensitive.
The response from OMDB is in Search
field not search
, so it should be
res.send(results["Search"][0]);
Upvotes: 1