0

I'm coding a small api in node.js (express) for my spine.js application. Getting and creating new objects in the database is working pretty well. But on deleting/editing I've git a problem right now. Every object gets an individual id created by the JS app. In the database every entry has a unique key, too.

When I call object.destroy() I can see the ajax request which is sent to my server. But as parameter for the id I always have the id which was given by the app. But for deleting/updating stuff in the database I need the key which is stored in the database (mongoDB in my case) So how can I send the right id to the server or identify the right entry on the server side!?

soupdiver
  • 3,504
  • 9
  • 40
  • 68

1 Answers1

1

Why not send the correct id back when creating your model like shown in the Spine documentation.

After a new Page record has been created, Spine sends a POST request to /pages containing the following:

  POST /pages HTTP/1.1 Host: spine-rails3.herokuapp.com Accept:
  application/json, text/javascript, */*; q=0.01 Content-Type:
  application/json; charset=UTF-8 X-Requested-With: XMLHttpRequest
  Content-Length: 65

  {"name":"Dummy page","id":"EEAF4B17-5F1D-4C06-B535-D9B58D84142F"}

Then the server should respond with something like this:

 HTTP/1.1 201 Created Content-Type: application/json; charset=utf-8
 Location: http://spine-rails3.herokuapp.com/pages/196 Content-Length:
 28 Connection: keep-alive

 {"name":"Dummy page","id":1}
Exploit
  • 108
  • 1
  • 9
  • I had a small error in my previous code.. thats what I still had the "old" id. It is working now thank you anyway :) – soupdiver Apr 10 '12 at 18:29