[Answered ]-How to post json to api method in backbone.js?

2👍

Backbone expects a RESTful api so instead of being the endpoint an action like create_obj, REST works with Resources and with HTTP methods. In your case you could have a Model like this:

var Obj = Backbone.Model.extend({
  defaults: {
     real_ref : '',
     share : ''
   }
});

and a collection like this

var Objects = Backbone.Collection.extend({
   url: 'myapp/obj',
   model: Obj
});

the collection has a propetry url that specifies the server endpoint. So the operations will be

  • POST /myapp/obj/ for create a new item
  • GET /myapp/obj/:id/ if you want to retreive an specific item
  • GET /myapp/obj/ retreving the whole list
  • PUT /myapp/obj/:id/ update an item
  • DELETE /myapp/obj/:id/ delete an item

Tastypie is a good framework to create RESTful api with Django.

Leave a comment