http rdf formats proxy
Express middleware for fetching and converting resources between RDF formats
install
npm install http-rdf-formats-proxy
In Express on GET /proxy
:
const express = const formatsProxy = const app = appappserver = app
usage
Currently rdf-formats-common formats are supported by default.
curl -H 'Accept: text/n3' 'http://localhost:8000/proxy?uri=http://example.com/resource.jsonld'curl -H 'Accept: text/turtle' 'http://localhost:8000/proxy?uri=http://example.com/resource.n3'curl -H 'Accept: application/ld+json' 'http://localhost:8000/proxy?uri=http://example.com/resource.n3'curl -H 'Accept: application/n-triples' 'http://localhost:8000/proxy?uri=http://example.com/resource.n3'
Proxy works both directions. You can POST data, convert them through proxy and it POSTs further.
Response is then converted to Accepted format. To specify format for proxy request, use produce
query parameter.
curl --data "<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> ." \ -H 'Content-type: n-triples' \ -H 'Accept: text/n3' \ 'http://localhost:8000/proxy?uri=http://example.com/consumer/&produce=application/ld+json'
Proxy can act as a converter. To use converter mode don't use any query parameter and just POST your data. Proxy will return the data converted according to the request's Accept header.
curl --data "<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> ." \ -H 'Content-type: n-triples' \ -H 'Accept: application/ld+json' \ 'http://localhost:8000/proxy'
tested cases
✓ no uri specified -> 400 Bad Request ✓ convert json+ld to n3 ✓ convert rdf+xml to n3 ✓ convert to unsupported/type should pass data through(?) ✓ pass non-rdf page data through(?) ✓ fetching a not existing page should pass 404 through ✓ fetching from a not existing server should yield 502(?) ✓ forward convert json+ld to n3 and response convert n-triples to n3 ✓ convert mode - json+ld to n-triples