I’m trying to use content negotiation to give both a HTML and a RDF/XML representation of a resource on a HTTP server. On the server side this works, i.e.
curl -H "Accept: application/rdf+xml" http://localhost:8182/ontologies/1
will retrieve the correct version. I can also do the same with JavaScript/Dojo:
function downloadOntologyRDF(ontologyId) {
dojo.xhrGet( {
url:"${baseUrl}/ontologies/" + ontologyId,
headers: {"Accept": "application/rdf+xml"},
timeout: 5000,
load: function(response, ioArgs) {
var preNode = document.createElement("pre");
preNode.appendChild(document.createTextNode(response));
var foo = new dijit.Dialog({
title: "RDF",
content: preNode,
style: "overflow: auto;"
});
foo.show();
return response;
},
error: function(response, ioArgs) {
alert("Retrieving the RDF version failed: " + response);
return response;
}
});
}
which will display the result in a popup dialog. The point where I am stuck is offering a way to the user to download this version. I would like to have a link on the page that either displays the RDF as a page in the browser or directly opens the save dialog. Is this possible at all without resorting to query parameters or other tricks?
Like cobbal mentions – since you can not set Accept header in the URL itself, you should have additional content negotiation mechanism. Some frameworks allow content type to be set in form
Having the
formatat the end of URL, separated with semicolon. Then, when processing request, it parses out the format part.In your case it could be something like
to server rdf, and no format specified to serve whatever is in your accept headers.