Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.Js Sending Data with destroy()

Tags:

backbone.js

I've got a basic social networking concept: Friend Requests.

Each friend request can either be accepted or declined, either action should result in the friend request being removed from the collection and deleted from the server.

I'm able to use model.destroy() to issue the DELETE request to the server and also remove the item from the FriendRequests collection. But I need to send some additional data to the server about whether the Request was accepted or declined. ?accepted=true|false

How do I do send additional data allong with Destroy() - or am I going about this the wrong way?

like image 490
reach4thelasers Avatar asked Nov 04 '22 23:11

reach4thelasers


1 Answers

I agree with @kinakuta that this is not a standard DELETE. Consider doing a PUT to /friend-request/42/accept or /friend-request/42/decline. Another option would be to do a standard update/PUT but on the server take the appropriate action when the accepted flag is provided during an update. You may also want to implement "soft delete" for your server side database records where the friend request doesn't actually get deleted but has its "status" attribute changed to the appropriate lifecycle value. Could be one of "pending", "declined", "accepted", etc. You may want to store additional metadata like a timestamp when the request was accepted, which could be interesting for reporting/analysis. If you delete the record, there's no convenient place to store that metadata.

like image 120
Peter Lyons Avatar answered Nov 09 '22 03:11

Peter Lyons