Abstracting the Backend
with NoBackend solutions.
Filip Petkovski
Every application is made up of two parts:
- The part which is unique for your app
- The part which is not
- Which one should you focus on?
Why can't we simply say:
account.signUp({
username: 'Filip',
password: 'NoPassword',
customFields: {...}
})
.then ( sayWelcome )
.fail ( failGracefully );
Prototyping
In the ideal case you:
- Develop quickly
- Host cheaply
- Focus on features and user experience
Prototyping
In reality:
- You set up a database
- You choose a programming language
- You pick a framework
- You model your data
- You build a basic API
- ...
- You start building your app
So again, why don't we simply:
products.add({
name: 'Coke',
description: 'Sugar in a can',
price: '$4.99'
})
.then ( ... )
.fail ( ... );
Enter NoBackend
-
NoBackend is a paradigm
-
Writing applications without focusing on the backend
-
Your apps become feature driven
- You actually don't need a backend programmer
Firebase - Dashboard
Firebase - Dashboard
Firebase - Dashboard
Firebase - Modifying data
// Push data
app.child('products').push({
name: ...,
description: ...,
price: ...,
owner: ...
}, callback);
// Set data
var id = 'some-id';
app.child('products').child(id).set({
...
}, callback);
// Update data
app.child('products').child(id).update({...}, callback);
...
<script src="https://cdn.firebase.com/js/client/1.0.24/firebase.js"></script>
...
// Firebase root handler
var app = new Firebase("https://best-app-ever.firebaseio.com");
Firebase - Reading data
var app = new Firebase("https://best-app-ever.firebaseio.com");
// Read data once:
app.child('products').once('value', function (snapshot) {
var data = snapshot.val();
// process data
});
// On value changed:
app.child('products').on('value', function (snapshot) {
var data = snapshot.val();
// process data
});
Firebase - Reading data
// On child added:
app.child('products').on('child_added', function (snapshot) {
var childAdded = snapshot.val();
// ...
});
// On child removed:
app.child('products').on('child_removed', function (snapshot) {
var removedChild = snapshot.val();
// ...
});
Firebase - Transactions
app.child('products/5/price').transaction(function (current) {
if (current < 10) {
return 0;
} else {
return 20;
}
});
Firebase - Authentication
var authClient = new FirebaseSimpleLogin(app, function(error, user) {
if (error) {
// an error occurred while attempting login
} else if (user) {
// user authenticated with Firebase
} else {
// user is logged out
}
});
authClient.login('password', {
email: '<email@domain.com>',
password: '<password>'
});
{
"rules": {
"products": {
"$product_id": {
".read": true,
".write": "auth.email == data.child('owner').val()",
".validate": "newData.hasChildren(['name', 'price'])",
"price": {
".validate": newData.isNumber() && newData.val() > 0
},
"name": {
".validate": !newData.exists()
}
}
}
}
}
Firebase - Security
- read rules
- write rules
- validation rules
Firebase - Going offline
- Every Firebase client stores data locally
- Data is the synchronized with Firebase servers
- In the case of a conflicts, last write wins
Deployd
-
Open source
-
Self hosted
- NodeJS + MongoDB
- Module based
$ git clone https://github.com/deployd/deployd.git
$ npm install
$ npm link
Deployd - Installation
$ dpd create best-app-ever
$ cd best-app-ever
$ dpd
starting deployd v0.6.10...
deployd v0.7.0 is available.
listening on port 2403
type help for a list of commands
dpd >
Deployd
Server side event handlers:
- Validation & Security
- Firing client-side events
Deployd
- MongoDB-like queries are supported
- Has a basic type system in place
- string, number, boolean, object, array
Other services
Thank you!
Text
https://github.com/fpetkovski/webcampzg2014
Abstracting the Backend.
By Filip Petkovski
Abstracting the Backend.
Abstracting the backend
- 1,932