It has been noted by Lèse that the javascript type null
is not a valid value for a URL parameter.
A javascript null
value should not be confused with the string 'null'
. Therefore, if you wish to include 'null'
in your URL like /comments/123?content=null
, you should provide the string 'null'
. Keep in mind that URL parameters are different from JSON and a null
value in javascript does not equate to content=null
where null would be considered a string value by most servers.
The $http service in Angular filters out null and undefined values when constructing a URL as there is no standard way to send undefined
as a value to a server. However, sending a string like 'undefined'
or 'null'
is acceptable, but it requires proper interpretation on the server side.
If you are making a PUT
request, consider why some data is being JSON serialized within the resource while other data is sent via a URL parameter. It may be more efficient to send the content
property and data in the JSON string to ensure the null
value is accurately represented. Additionally, consider using a DELETE
request instead of aliasing a destroy method with a PUT request when deleting records.
Instead of the current approach, perhaps try something like the following example involving a User
:
var Comment = $resource('/comments/:id', {id: @id}, {
destroy: {method: 'PUT'}
});
new Comment({id: 123, content: null}).$destroy();