I use this code to create requests for a server with a MongoDB server (using angular and lodash):
.factory('mongoQuery', function() { return { fromJson: function(json) { return JSON.parse(json, fromJsonReviver); }, toJson: function(object) { return JSON.stringify(object, toJsonReplacer); } }; function fromJsonReviver(key, value) { var val = value; if (_.isPlainObject(value)) { if (_.isNumber(value.$date)) { val = new Date(0); val.setUTCMilliseconds(value.$date * 1000); } else if (_.isString(value.$regexp)) { var match = /^\/(.*)\/([gimy]*)$/.exec(value.$regexp); val = new RegExp(match[1], match[2]); } } return val; } function toJsonReplacer(key, value) { var val = value; if (_.isPlainObject(value)) { val = _.extend({}, value); for (var k in value) { val[k] = toJsonReplacer(k, val[k]); } } else if (_.isDate(value)) { val = {$date: (new Date(value)).valueOf() / 1000}; } else if (_.isRegExp(value)) { val = {$regexp: value.toString()}; } return val; } })
It includes many of the sentences mentioned by others in the comments, and supports dates and regular expressions.
Other than that, if you need to send a request using a GET request, just use encodeURIComponent , as others have mentioned.
Here is a working example: http://plnkr.co/edit/b9wJiUkrHMrDKWFC1Sdd?p=preview
source share