Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Created September 22, 2015 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcassel/531f9ed2bdc912fd8700 to your computer and use it in GitHub Desktop.
Save dmcassel/531f9ed2bdc912fd8700 to your computer and use it in GitHub Desktop.
xdmp.setResponseContentType("application/json");
switch(xdmp.getRequestMethod()) {
case "GET":
// Get the criterion out of the URL query string
var q = cts.wordQuery(xdmp.getRequestField("q"));
// Unwind the iterator into an Array
var results = cts.search(q).toArray();
xdmp.addResponseHeader("X-Result-Count", results.length + "");
// Serialize the JavaScript results object as JSON
xdmp.toJSON(results);
break;
default:
xdmp.setResponseCode(405, "Method not allowed");
{ message: "Only GET requests are allowed" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment