var params, email, resource, result;
var lodash = require(“lodash.min.js”);
if (event.request.method !== “GET”) {
throw(“Only HTTP GET is allowed on this service.”);
}
// get query params from request
params = event.request.parameters;
resource = event.resource;
if (resource !== “”) {
// check for required params
required = [“email”];
lodash._.each( required, function( element ) {
if (!params.hasOwnProperty(element) || !params[element]) {
throw( “Missing '” + element + “’ in params\n” );
}
});
email = params.email;
// filter by email
var params = {
"filter": "email=" + email
}
// get matching record from MongoDB service
var result = platform.api.get("mongodb/_table/address_details", params);
return result;
}