I’m using SWI-Prolog, both semweb and HTTP libraries at the same time. Now I want to return a turtle file in an API, which seems to be possible because rdf_save_turtle saves to a stream and http_reply should be able to return from a stream.
However, I’m not able to make it work.
:- http_handler(root('_api/query'), query, [method(get)]).
query(Request) :-
stream_property(Response, write),
format('Content-Type: text/turtle~n~n'),
rdf_save_turtle(Response, []).
According to the docs, in the query term, there’s a default output stream (used by format) which is the HTTP output. However, I’m not able to get it with stream_property so I can’t pass to rdf_save_turtle a valid output stream.
How could you get the default output stream?
This is double posted at StackOverflow.