KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm using backbone.js to interact with a REST API that, when posting to it to create a new resource, responds with a status of 201, a 'Location' header pointing to the resource's URI, but an empty body. When I create a new model at the moment, its successful, but the local representation of the model only contains the properties I explicitly set, not any of the properties that would be set on the server (created_date, etc.) From what I understand, Backbone would update its representation of the model with data in the body, if there were any. But, since there isn't, it doesn't. So, clearly, I need to use the location in the Location header to update the model, but what's the best way to do this. My current mindset is that I would have to parse the url from the header, split out the id, set the id for the model, then tell the model to fetch(). This seems really messy. Is there a cleaner way to do it? I have some influence over the API. Is the best solution to try to get the API author to return the new model as the body of the response (keeping the 201 and the location header as well)? Thanks!
Tags (comma-separated)
Save Edits
Cancel