Install dependencies
Create: server.js
Create film-data.json
Start the server
You can download and run the full source without the need to install any dependencies: https://github.com/stevenh77/simple-rest-express-server
You can download and run the full source without the need to install any dependencies: https://github.com/stevenh77/simple-rest-express-server
UI devs love to be able to work independently of server teams, which is where API mocking can really help out.
Quickly knock up a few end points with test data and responses returned – takes no time at all.
Great for building little working prototypes with REST service requests.
A linked list would be a more logical representation of stations for a train line but for this example we’re using a list.
Check out this scalable, easy to use, web data storage for real time apps.
Example:
Firebase along with loads of cool demo apps and quickstart tutorials can be found here: http://firebase.com
There’s also a web UI from administering your web db.
Try this out for yourself by spinning up a couple of browsers: http://stevenhollidge.com/blog-source-code/firebase/index.html
Bear in mind the data is shared so whatever you type will appear above, be nice :)
Source:
<html>
<head>
<script src='https://cdn.firebase.com/v0/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
</head>
<body>
<div id='messagesDiv'></div>
<input type='text' id='nameInput' placeholder='Name'>
<input type='text' id='messageInput' placeholder='Message'>
<script>
var myDataRef = new Firebase('https://d5wez3l3q02.firebaseio-demo.com/');
$('#messageInput').keypress(function (e) {
if (e.keyCode == 13) {
var name = $('#nameInput').val();
var text = $('#messageInput').val();
myDataRef.push({name: name, text: text});
$('#messageInput').val('');
}
});
myDataRef.on('child_added', function(snapshot) {
var message = snapshot.val();
displayChatMessage(message.name, message.text);
});
function displayChatMessage(name, text) {
$('<div/>').text(text).prepend($('<em/>').text(name+': ')).appendTo($('#messagesDiv'));
$('#messagesDiv')[0].scrollTop = $('#messagesDiv')[0].scrollHeight;
};
</script>
</body>
</html>
It’s written in Scala and they take care of the eventual consistency and scalability issues which leaves the developer to focus on the business problem. There’s also lots of bindings available including Angular and Ember.
Enjoy!