Created
September 22, 2015 17:12
-
-
Save dmcassel/531f9ed2bdc912fd8700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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