I have a RESTful service that performs a search and returns the results as JSON, and if there’s no results I return an empty document, {}.
Calling this search from AngularJS with $http.get(), I get the returned JSON result and everything is good if I have a document containing data, but an empty document took a bit more Googling to work out how to detect it.
From this similar question, I don’t want to use jQuery in my AngularJS app if I can avoid it (although doesn’t AngularJS have a “jQuery lite” api that maybe I can use?), so I used this approach instead:
[code]
if(Object.keys(data) == 0) { … }
[/code]
http://george.hotelling.net/91percent/2015/05/17/restful-responses-and-angular/ Thanks for the RESTful tips for returning an empty result – I was’t aware of this approach, so this is good to know!