When dealing with rest services, I think the practice is to send back the url of the newly created object so that it can be shown to return user to update the object that was POSTed.
http://en.wikipedia.org/wiki/Representational_State_Transfer
“Create a new entry in the collection. The new entry's URL is assigned automatically and is usually returned by the operation.”
So I would say { url: “book/123” }
Does this help?
--dan
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/N1QZCbhF19oJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1424 / Virus Database: 2113/4886 - Release Date: 03/22/12
function FormCntl($resource) {
this.bookModel = $resource('/book/:id', {id: '@id'});
}
FormCntl.$inject = ['$resource']
FormCntl.prototype = {
fetch: function(){
this.book = this.bookModel.get({id: this.id});
},
save: function(){
this.book = this.bookModel.get({id: this.id}); //This wasn't obvious as I glanced through the docs. What is the best way to pass the form parameters?
}
}
# a simple Google App Engine webservice to support the book model.
import webapp2 as webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson as json
from google.appengine.ext import db
class Book(db.Model)
title = db.StringProperty()
class BookHandler(webapp.RequestHandler):
def get(self, model,id):
#Fetch the model and return the properties as JSON. Not too hard.
book = Book.get_by_id(int(id))
result = #Build the json doc from the model
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(result))
def post(self,model,id):
title = self.request.get('title','default post title')
book = Book.get_by_id(int(id))
book.title = title
book.put()
result = #Build the json doc from the model
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(result))
return
def main():
application = webapp.WSGIApplication(
[('/([^/]+)/?([0-9]*)', BookHandler)],
debug=True)
run_wsgi_app(application)