Skip to content

Instantly share code, notes, and snippets.

@MikeBild
Last active December 12, 2015 14:39
Show Gist options
  • Save MikeBild/2997ab19527e5cd88ff8 to your computer and use it in GitHub Desktop.
Save MikeBild/2997ab19527e5cd88ff8 to your computer and use it in GitHub Desktop.
Order Line API
const request = require('request-promise');
state.orders = state.orders || [];
this.GET = getOrders;
this.POST = startOrderProcess;
this.DELETE = abortOrder;
if(!this[req.method]) return res.status(404).end();
this[req.method](req.params, req.body);
function getOrders(params) {
var orderId = params.id;
if(state.orders[orderId]) return res.send(state.orders[orderId]);
res.send(state.orders);
}
function startOrderProcess(params, body){
console.log('Start order process');
let orderData = body;
console.log(JSON.stringify(orderData));
request('https://mikebild.service.subkit.io/reserve')
.then(result => {
res.status(201).send(result);
})
.catch(error => res.status(500).send(error));
}
function abortOrder(params, body){
var orderId = req.params.id;
console.log('Abort order process');
console.log(orderId);
res.status(201).end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment