Skip to content

Instantly share code, notes, and snippets.

@apb2006
Created February 25, 2017 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 apb2006/538f3feb6dd50789c4c618115b3dce61 to your computer and use it in GitHub Desktop.
Save apb2006/538f3feb6dd50789c4c618115b3dce61 to your computer and use it in GitHub Desktop.
restxq returning json with cors header
(:~
: JSON test apb feb 2017
:)
module namespace page = 'json-test';
(: test data :)
declare variable $page:data:=<json objects="json _">
<total type="number">15</total>
<entity>app</entity>
<items type="array">
<_>
<name type="string">abide</name>
<uri type="string">/abide</uri>
<description type="string">todo this</description>
</_>
</items>
</json>
;
(:~ CORS header :)
declare function page:headers(){
<restxq:response>
<http:response>
<http:header name="Access-Control-Allow-Origin" value="*"/>
</http:response>
</restxq:response>
};
declare %rest:path("/json")
%output:method("json")
function page:json(){
(page:headers(),
$page:data
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment