I am new to javascript / web application and trying to implement my first web application using hunchentoot and backbone.js. The first thing I experimented with was understanding how the model.fetch () and model.save () functions work.
It seems to me that model.fetch () is launching a "GET" request, and model.save () is launching a "POST" request. So I wrote a simple handler in hunchentoot, as shown 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 ....))))
It is designed to handle fetching / saving a model whose corresponding URL is "/ dataset". The fetch file works fine, but I'm confused by saving (). I saw that the "post" request was launched and processed using a simple 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 from the post post that model.save () launched, so that a later json library (like jsown) can be used to parse it?
- What should hunchentoot answer so that the client knows what to βsaveβ successfully?
I tried the post-parameters function in hunchentoot and it returns nil, and have not seen many people using hunchentoot + backbone.js with googling. It is also useful if you can direct me to some articles / blogs that help to understand how backbone.js save () works.
Thanks so much for your patience!
source share