Look at the API for $httpbackend
, we can see that functions like expectPut
can take up to 4 parameters. The second parameter can be a function which takes 1 parameter: a string. This string represents the body of the HTTP request.
But why is it a string? Wouldn't it make more sense for it to be JSON? Is there a technical reason why Angular needs to give me the body back as a string instead of JSON?
HTTP request bodies are strings, it doesn't really make sense to represent them in any other way.
In this instance you may be passing an object to the function, but in a real webrequest it won't make it to the server as an object, it will be a string representation of the object. Equally, it could be any other string - there's no way angular could parse and pass any given string as an object to the callback.
There's nothing stopping you from serialising your request as a string (or letting angular do it internally), then parsing it as JSON within the callback function if that's what you're expecting.