Search code examples
javascriptbackbone.jslocalhost

Do I need any server script to save() / fetch() Backbone model to localhost?


Please, explain me the following thing, for I failed to find an answer so far and just don't get it.

The thing is that I've just started to learn Javascript client side on Backbone. I want to practice model.save() / model.fetch(), etc. Say, let's take some code like:

var Model = Backbone.Model.extend({
    urlRoot: "someUrl"
});
var model = new Model({'name': 'Peter'});
model.save();

Do I necessarily need any server-side script to save and fetch my model? Server-side is a completely new thing to me. Is there a way for me to try model.save() and model.fetch() and similar Backbone things on localhost without having to start learning php or things like that right now? I'm stuck at this point.

I hope somebody can give me a simple solution, like: Install this and that, do this and that, and now you can save, fetch, delete your backbone models on your localhost server and move further in your learning. Thanks in advance.


Solution

  • Fortunately no! You do not need a backend server. Your backend can be the client. For example: the localStorage API. And lucky you, you can use a localStorage plugin for Backbone like Backbone.localStorage.

    Another option you can use is IndexedDB that also has its share of plugins like this one.