Skip to content

Instantly share code, notes, and snippets.

@TheIronDev
Last active August 29, 2015 14:13
Show Gist options
  • Save TheIronDev/69de8b6273586f155d2b to your computer and use it in GitHub Desktop.
Save TheIronDev/69de8b6273586f155d2b to your computer and use it in GitHub Desktop.
A dummy in-memory store mock ember-cli example
module.exports = function(app) {
var express = require('express');
var postsRouter = express.Router();
var posts = [],
count = 1;
postsRouter.get('/', function(req, res) {
res.send({
'posts': posts
});
});
postsRouter.post('/', function(req, res) {
var newPost = {
id: count,
title: '',
description: ''
};
req.on("data",function(chunk){
var thing = JSON.parse(chunk.toString()),
post = thing.post;
newPost.title = post.title;
newPost.description = post.description;
});
req.on("end",function(){
res.send({
post: newPost
});
posts.push(newPost);
count++;
});
});
postsRouter.get('/:id', function(req, res) {
res.send({
'posts': {
id: req.params.id
}
});
});
postsRouter.put('/:id', function(req, res) {
res.send({
'posts': {
id: req.params.id
}
});
});
postsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/posts', postsRouter);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment