Skip to content

Instantly share code, notes, and snippets.

@crizstian
Last active February 12, 2017 20:24
Show Gist options
  • Save crizstian/05898db671bd8cd469f8ad1cef3c3726 to your computer and use it in GitHub Desktop.
Save crizstian/05898db671bd8cd469f8ad1cef3c3726 to your computer and use it in GitHub Desktop.
Example of an API
'use strict'
const status = require('http-status')
module.exports = ({repo}, app) => {
app.post('/payment/makePurchase', (req, res, next) => {
const {validate} = req.container.cradle
validate(req.body.paymentOrder, 'payment')
.then(payment => {
return repo.registerPurchase(payment)
})
.then(paid => {
res.status(status.OK).json({paid})
})
.catch(next)
})
app.get('/payment/getPurchaseById/:id', (req, res, next) => {
repo.getPurchaseById(req.params.id)
.then(payment => {
res.status(status.OK).json({payment})
})
.catch(next)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment