Quickstart

You want to see code right? Not pages of academic prose?
Click on the underlined parts in the code section to reveal
what other things can be done.

How to read from the server. Use the + and - buttons, and click the underlined words to alter the query and explore what's available.
How to write to the server. TL;DR: It's not much different than vanilla JavaScript.
var bob = new Employee(); bob.name = "Bob"; bob.salary = 50000; Upload a file by assigning to the .photo property. bob.photo = document.querySelector("INPUT[type=file]"); bob.photo.onprogress = percentage => alert(percentage + "% complete."); bob.photo.oncomplete = success => alert(success ? "Upload complete" : "Upload failed"); Adding strings to a member array: bob.alternateNames.push("Robert", "Mr. Smith"); Adding objects to a member array: var office = new Office(); office.employees.push(bob); Arrays can hold multiple references to the same object: office.employees.unshift(bob); Delete all 'bob' objects from the array with .delete() instead of .splice(): office.employees.delete(bob); Or just empty out the entire array with: office.employees.clear(); Self-referencing assignments: bob.nominatesForBoard = bob; Bidirectional references: var paul = new Employee(); var kim = new Employee(); paul.nominatesForBoard = kim; kim.nominatesForBoard = paul; Wait until everything above has been written to the server Back.then(error => { error ? alert("Something went wrong: " + error) : alert("All written."); });
How to authenticate users. When a class is marked as a having authentication behavior in the Back I/O editor, the classes and objects gain special powers.
Checking if an employee exists: Employees.exists("milton@initech.com", exists => { exists ? alert("Milton exists.") : alert("Milton doesn't exist."); }); Logging in an existing user with email and password: Employees.login("a@b.com", "pass", (e, employee) => { alert("Logged in."); }); Logging in an existing user though Facebook (it's the same for the other OAuth providers). Employees.login(oauthResult, (e, employee, accessToken) => { alert("Logged in. We can use accessToken to call provider-specific APIs."); }); Creating a new user, and logging them in: var employee = new Employee(); employee.login("a@b.com", "pass", (e, employee) => { alert("Logged in."); }); Logging out employee.logout();
How to watch for changes. All Back I/O objects have .watch() and .unwatch() methods.
var watchEverythingFn = employee.watch(changedPropertiesArray => { alert(changedPropertiesArray.length + " properties just changed."); }); var watchNameFn = employee.watch(Employee.name, () => { alert("The employee's .name changed."); }); employee.unwatch(watchEverythingFn); employee.unwatch(watchNameFn);
How to catch errors.
Back.on() method returns a reference to your handler function: var fn1 = Back.on(Back.MisuseError, error => alert("Likely passed a bad parameter to a method.")); var fn2 = Back.on(Back.NetworkError, error => alert("Internet service is out, or just flakey.")); var fn3 = Back.on(Back.AccessError, error => alert("Something was attempted that's not allowed for the current user.")); var fn4 = Back.on(Back.UnexpectedError, error => alert("There's a bug in Back I/O")); Pass the handler function to Back.off() to stop catching errors: Back.off(fn1); Back.off(fn2); Back.off(fn3); Back.off(fn4);