As Lez noted, the javascript null type is not a valid value for the URL parameter.
The javascript null value does not match the string 'null' . Therefore, if you want your URL to look like /comments/123?content=null , just specify the string 'null' . URL parameters are not JSON, and null in javascript does not mean the same as content=null , because in the latter case, null will be interpreted by any given server as a string value.
Angular $ http service filters out the null and undefined values โโin the params object before creating the url with them , because there is no standardized way to send undefined as a "value" to the server. It just doesn't make sense. However, if you want to send a string such as 'undefined' or 'null' , thatโs fine, but interpreting it requires a server-side implementation.
If you make a PUT request, why are some of your data JSON-serialized inside the resource, and some are sent via the URL parameter? Maybe the sample code is simply poorly presented, but in this example you send a PUT request with the response body {"id": 123} and url /comments/123 . Isn't that redundant? Why arenโt you sending the content property and data in the JSON string to the server? Then it will actually be the null value you are looking for, because JSON strings can represent a null value. Also, if you delete / destroy a record, why don't you use the DELETE request, and instead impose a destruction method using the PUT request?
So why not? I'm not sure what User is associated with it ...
var Comment = $resource('/comments/:id', {id: @id}, { destroy: {method: 'PUT'} }); new Comment({id: 123, content: null}).$destroy();
jbielick
source share