Monday 24 April 2017

NodeJs rest can't find GET method with query

Hi, I wanted to make a test for a REST app.This is the url I use: localhost:3000/movies/find?year=2011&orderby=titlerouter.use('/movies', movieService);And this is the code I wrote:// GET movie ids by query params router.get('/find', (req, res) => { let yearParam:Number = req.query.year; let fieldParam:String = req.query.orderby; console.log(yearParam); var moviesByYear = new Array(); Movie.find({}, (err, movies) => { if (err) res.send(err); for (var i = 0; i < movies.length; i++) { if (movies[i].year == yearParam) { moviesByYear.push(movies[i]); } } if (fieldParam == "title") { moviesByYear.sort(compareMoviesByTitle); } else if (fieldParam == "director") { moviesByYear.sort(compareMoviesByDirector); } var newMovieIdList = new MovieIdList(); for (var i = 0; i < moviesByYear.length; i++) { newMovieIdList.id.push(moviesByYear[i].id); } res.json(newMovieIdList); }); }); When I try to get the results it does nothing...GET /movies/find?year=2011&orderby=title 200 4.293 ms - -

Submitted April 24, 2017 at 07:37PM by gabegabe6

No comments:

Post a Comment