Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created September 22, 2016 03:06
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 baskaufs/00f471b905ae9b862677fedf9f047bcb to your computer and use it in GitHub Desktop.
Save baskaufs/00f471b905ae9b862677fedf9f047bcb to your computer and use it in GitHub Desktop.
restxq module with content negotiation that fails with a browser
module namespace page = 'http://basex.org/modules/web-page';
declare
%rest:path("/{$id}")
%rest:GET
%rest:produces("text/turtle")
function page:turtle($id)
{
<rest:response>
<output:serialization-parameters>
<output:media-type value='text/turtle'/>
</output:serialization-parameters>
</rest:response>,
'<http://ex.org/my><http://ex.org/example>"Turtle text".'
};
declare
%rest:path("/{$id}")
%rest:GET
%rest:produces("application/rdf+xml")
function page:xml($id)
{
<rest:response>
<output:serialization-parameters>
<output:media-type value='application/rdf+xml'/>
</output:serialization-parameters>
</rest:response>,
<example>this is RDF/XML</example>
};
declare
%rest:path("/{$id}")
%rest:GET
%rest:produces("application/json")
function page:json-ld($id)
{
<rest:response>
<output:serialization-parameters>
<output:media-type value='application/json'/>
</output:serialization-parameters>
</rest:response>,
'{"this":"is RDF/JSON"}'
};
declare
%rest:path("/{$id}")
%rest:GET
%rest:produces("text/html","application/xhtml+xml")
function page:html($id)
{
<rest:response>
<output:serialization-parameters>
<output:media-type value='text/html'/>
</output:serialization-parameters>
</rest:response>,
<html><body>this is a web page</body></html>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment