Last active
January 22, 2017 20:46
-
-
Save crizstian/b8db4c2f9aaa3667b099f49bb6d374a8 to your computer and use it in GitHub Desktop.
Example of movie service API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const status = require('http-status') | |
module.exports = (app, options) => { | |
const {repo} = options | |
// here we get all the movies | |
app.get('/movies', (req, res, next) => { | |
repo.getAllMovies().then(movies => { | |
res.status(status.OK).json(movies) | |
}).catch(next) | |
}) | |
// here we retrieve only the premieres | |
app.get('/movies/premieres', (req, res, next) => { | |
repo.getMoviePremiers().then(movies => { | |
res.status(status.OK).json(movies) | |
}).catch(next) | |
}) | |
// here we get a movie by id | |
app.get('/movies/:id', (req, res, next) => { | |
repo.getMovieById(req.params.id).then(movie => { | |
res.status(status.OK).json(movie) | |
}).catch(next) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment