I am a javascript/web application newbie and trying to implement my first web application using hunchentoot and backbone.js. The first thing I was experimenting is to understand how model.fetch() and model.save() work.
It seems to me that model.fetch() fires a "GET" request and model.save() fires a "POST" request instead. Therefore, I wrote a easy-handler in hunchentoot as below:
(hunchentoot:define-easy-handler (dataset-handler :uri "/dataset") ()
(setf (hunchentoot:content-type*) "text/html")
;; get the request type, canbe :get or :post
(let ((request-type (hunchentoot:request-method hunchentoot:*request*)))
(cond ((eq request-type :get)
(dataset-update)
;; return the json boject constructed by jsown
(jsown:to-json (list :obj
(cons "length" *dataset-size*)
(cons "folder" *dataset-folder*)
(cons "list" *dataset-list*))))
((eq request-type :post)
;; have no idea on what to do here
....))))
This is designed to handle the fetch/save of a model whose corresponding url is "/dataset". The fetch works fine, but I got really confused by the save(). I saw the "post" request fired and handled by the easy-handler, but the request seems to have only a meaningful header, I cannot find the actual json object hidden in the request. So my question is
- How can I get the json object out of the post request fired by model.save(), so that later json library (e.g., jsown) can be used to parse it?
- What should hunchentoot reply in order to let the client know that the "save" is successful?
I tried "post-parameters" function in hunchentoot and it returns nil, and didn't see many people using hunchentoot+backbone.js by googling. It is also helpful if you can direct me to some articles/blog posts that help understanding how the backbone.js save() works.
Thank you very much for your patience!
raw-post-data
is the correct answer. I actually tried this before asking the question, but fed it with the wrong argument. – Irmine