Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
Key Takeaways
Syncs Backbone.js models with the server
Full Transcript
backbone applications often but not always use models that are synchronized with a persistent store using restful API on the server backbone models provide an abstraction over the low-level API communication which results in a cleaner and simpler code for example instead of you manually making ax calls to the server to fetch the data you simply call the fetch method on your model the model would then take care of making an ax Call to get the data backbone models support three operations to work with the persistent store fetch to get the model from the server save to insert or update the model and Destroy to delete the model depending on the method you call backmon Will issue a get post put or delete HTTP request for example fetch always issues a get request save depending on the state of the object makes a post or a put request if the object is new it sends a post request otherwise it sends a put request how does backone know if the object is new or not well if it's been fetched from the server before it assumes that it's an existing object otherwise it assumes that it's a new object until it's Sav to the server and finally destroy always results in a delete request now you may wonder how backbone knows the URL of the API backbone relies on the URL root property of your models to construct the URL to the corresponding endpoint if you don't specify the URL route and call one of the operations to sync with the server you'll get an error that the URL is not defined so in this example we are telling backbone that all our songs are located at forward slash API songs on the server so if our website is hosted at example.com that will translate to example.com API songs now let's look at some specific examples in this slide I'm showing how we can fetch a model from the server so we are instantiating a song object with the idea one and calling the fetch method which results in an HTTP get to/ API songs1 here is another one in this example we construct a song object we fetch it from the server then we update the title property and find it called the save method in this case because the object has been fited from the server before it's an existing object and as a result backbone will issue a put request to/ API songs1 here is another one here we are instantiating a new song object setting its property and calling the Save which will result in a post request to the song's collection and finally here is another example where we destroy a model in which case a delete request is sent to/ API song1 note that by convention magon assumes your models have an attribute called ID which is used for uniquely identifying them if you use a different convention you can use the ID attribute to tell backbone which property of your model is used as the identifier in this example we are telling backbone that song ID should be used as the ID attribute not that all these methods are asynchronous and except a success and error call back the syntax is a little bit tricky and I have noticed many developers get stuck with this and think there's a bug and backbone so let me clarify this Fetch and Destroy are the easy ones just Supply the Callback functions as you see in the slide the save method however is a little bit different with the save method our callback functions are wrapped with an object that is the second argument to the save method not the first one the first argument is a hash of the attributes you would like to change it's kind of a shortcut that lets you pass the attributes here and save them to the server it's similar to setting them using the set method and then calling the save method so I personally always set values using the set method and then call the save method with an empty object as the first argument or you can also pass a null object note that if you accidentally forget to pass the first argument your success and error callbacks won't be executed upon return from the server so that's the tricky part okay at this point you should have a good understanding of models and how to work with them before proceeding to the next section make sure to take the many project that I've included at the end of this section if you have any questions feel free to post them in the discussions area I'm here to help you thank you for watching
Original Description
Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
This video is part of my 4-hour Udemy course where I take you on a step-by-step journey to learn Backbone.js from scratch to a level to start building real-world applications with it. Throughout the course, I’ll show you many real-world examples of popular websites such as Facebook, Twitter, Bitly, FourSquare, Pinterest, etc and explain how you would implement something like them with Backbone.
I'll also give you cheat sheets and assignments to put what you learn in practice. You'll also get the benefit of asking me any questions and I'll help you out throughout your learning.
If you’re interested, you can get the course with a discount coupon here:
https://www.udemy.com/backbonejs-tutorial/?couponCode=utube
More free Backbone.js tutorials on my channel:
Backbone.js Models
Creating Models http://youtu.be/4t0n5k0X7ow
Working with Model Attributes http://youtu.be/FXlSC1gcs7E
Model Validation http://youtu.be/niYCJOMZPJw
Inheritance http://youtu.be/FfQT31gZWp8
Syncing Models with the Server http://youtu.be/AvhdNKmmAXU
Backbone.js Collections
Creating Collections http://youtu.be/ZnGP9ScI9pc
Working with Collections http://youtu.be/NjCF_7bpKjw
Fetching Collections from the Server http://youtu.be/jbiqBchPfKw
Backbone.js Views
Creating Views http://youtu.be/QASCp8PyRXM
Passing Data to Views http://youtu.be/QkHeKnjNuWA
Handling the DOM Events http://youtu.be/dC0LVPZedZA
Handling the Model Events http://youtu.be/tTRy_GluLac
Handling the Collection Events http://youtu.be/kh6ehZ1BCUk
Templating in Views http://youtu.be/BFAGGPgi0ec
Take my full 4-hour Udemy course to also learn about:
Backbone.js Routers
Backbone.js Events
Testing Backbone.js Applications with Jasmine
Modularizing Bakcbone.js Applications with Require.js
Building an Application from Scratch with Backbone.js
Get the full course with 30% discount here:
https://www.udemy.com/backbonejs-tutorial/?couponCode=byt70
Faceb
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Programming with Mosh · Programming with Mosh · 7 of 60
1
2
3
4
5
6
▶
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
6 Visual Studio Tips to Increase Your Productivity | Mosh
Programming with Mosh
Visual Studio Keyboard Shortcuts that Speed Up Debugging Applications | Mosh
Programming with Mosh
Backbone.js Tutorial Part 2 - Backbone.js Models: Working with Model Attributes
Programming with Mosh
Backbone.js Tutorial Part 3 - Backbone.js Models: Model Validation
Programming with Mosh
Backbone.js Tutorial Part 4 - Backbone.js Models: Model Inheritance
Programming with Mosh
Backbone.js Tutorial Part 1 - Backbone.js Models: Creating Models
Programming with Mosh
Backbone.js Tutorial Part 5 - Backbone.js Models: Syncing Models with the Server
Programming with Mosh
Backbone.js Tutorial Part 6 - Backbone.js Collections: Creating Collections
Programming with Mosh
Backbone.js Tutorial Part 7 - Backbone.js Collections: Working with Collections
Programming with Mosh
Backbone.js Tutorial Part 8 - Backbone.js Collections: Fetching Collections from the Server
Programming with Mosh
Backbone.js Tutorial Part 9 - Backbone.js Views: Creating Views
Programming with Mosh
Backbone.js Tutorial Part 10 - Backbone.js Views: Passing Data to Views
Programming with Mosh
Backbone.js Tutorial Part 11 - Backbone.js Views: Handling the DOM Events
Programming with Mosh
Backbone.js Tutorial Part 12 - Backbone.js Views: Handling the Model Events
Programming with Mosh
Backbone.js Tutorial Part 13 - Backbone.js Views: Handling Collection Events
Programming with Mosh
Backbone.js Tutorial Part 14 - Backbone.js Views: Templating
Programming with Mosh
Clean Code: Learn to write clean, maintainable and robust code
Programming with Mosh
C# Events and Delegates Made Simple | Mosh
Programming with Mosh
C# Generics Tutorial: Whats and Whys | Mosh
Programming with Mosh
Debugging C# Code in Visual Studio | Mosh
Programming with Mosh
Repository Pattern with C# and Entity Framework, Done Right | Mosh
Programming with Mosh
Angular 2 Tutorial for Beginners: Learn Angular 2 from Scratch | Mosh
Programming with Mosh
Architecture of Angular 2+ Apps
Programming with Mosh
Working with Components in Angular
Programming with Mosh
C# Tutorial For Beginners - Learn C# Basics in 1 Hour
Programming with Mosh
Difference between Junior and Senior Developers
Programming with Mosh
Step-by-step ASP.NET MVC Tutorial for Beginners | Mosh
Programming with Mosh
[Pluralsight]: Become a Full-stack .NET Developer
Programming with Mosh
Xamarin Forms Tutorial: Build Native Mobile Apps with C#
Programming with Mosh
Value Types and Reference Types in JavaScript
Programming with Mosh
Using Redux in Angular 2+ Apps | Mosh
Programming with Mosh
Testing Angular 2+ Apps with Jasmine and Karma | Mosh
Programming with Mosh
Profile and optimize your Angular 2 apps
Programming with Mosh
Build a Real-world App with ASP.NET Core and Angular 2
Programming with Mosh
Entity Framework 6 Tutorial: Learn Entity Framework 6 from Scratch
Programming with Mosh
Two-way Binding and ngModel in Angular 4
Programming with Mosh
Udemy Live 2017: Teaching Tech Panel
Programming with Mosh
Demo of An E-commerce App Built with Angular, Firebase and Bootstrap 4
Programming with Mosh
My Brand New Angular Course
Programming with Mosh
TypeScript Tutorial - TypeScript for React - Learn TypeScript
Programming with Mosh
Access Modifiers in TypeScript
Programming with Mosh
TypeScript Interfaces
Programming with Mosh
TypeScript Classes
Programming with Mosh
TypeScript Constructors
Programming with Mosh
TypeScript Properties
Programming with Mosh
Angular Tutorial for Beginners: Learn Angular & TypeScript
Programming with Mosh
AngularJS vs Angular 2 vs Angular 4 | Mosh
Programming with Mosh
Angular Material Tutorial | Mosh
Programming with Mosh
Angular Animations Tutorial | Mosh
Programming with Mosh
Firebase in Angular Applications | Mosh
Programming with Mosh
Deploying Angular Applications | Mosh
Programming with Mosh
Building Forms in Angular Apps | Mosh
Programming with Mosh
Directives in Angular Applications
Programming with Mosh
Routing and Navigation in Angular | Mosh
Programming with Mosh
Angular 4 in 40 Minutes
Programming with Mosh
[NEW COURSE] Unit Testing for C# Developers
Programming with Mosh
Unit Testing C# Code - Tutorial for Beginners
Programming with Mosh
C# Classes Tutorial | Mosh
Programming with Mosh
C# Object Initializers Tutorial
Programming with Mosh
C# Constructors Tutorial | Mosh
Programming with Mosh
🎓
Tutor Explanation
DeepCamp AI