Skip to content

Instantly share code, notes, and snippets.

@crizstian
Last active January 22, 2017 20:46
Show Gist options
  • Save crizstian/b8db4c2f9aaa3667b099f49bb6d374a8 to your computer and use it in GitHub Desktop.
Save crizstian/b8db4c2f9aaa3667b099f49bb6d374a8 to your computer and use it in GitHub Desktop.
Example of movie service API
'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