<h3>1. genarate ember project with ember-cli</h3>
<h3>2. it comes with expressjs (hhtp-mock); run </h3>
<pre>ember g http-mock destinations</pre>
<h3>3. to view: http://localhost:4200/api/destinations</h3>
<h3>ref: </h3>
<ul><li>https://discuss.emberjs.com/t/how-i-use-ember-cli-with-http-mock/7403</li>
<li>Discourse uses ember.js</li></ul>
<h3>4. setting up a mock response</h3>
<pre>
/*jshint node:true*/
module.exports = function(app) {
var express = require('express');
var destinationsRouter = express.Router();
destinationsRouter.get('/', function(req, res) {
res.send({
'destinations': [
{
id:'001',
loc: 'colombo'
}, {
id:'002',
loc: 'singapore'
}, {
id:'003',
loc: 'kuala lumpur'
}
]
});
});
destinationsRouter.post('/', function(req, res) {
res.status(201).end();
});
destinationsRouter.get('/:id', function(req, res) {
res.send({
'destinations': {
id: req.params.id
}
});
});
destinationsRouter.put('/:id', function(req, res) {
res.send({
'destinations': {
id: req.params.id
}
});
});
destinationsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// npm install --save-dev body-parser
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
//
//app.use('/api/destinations', require('body-parser').json());
app.use('/api/destinations', destinationsRouter);
};
</pre>
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.