Express middleware for fetching and converting resources between RDF formats
npm install http-rdf-formats-proxy
In Express on GET /proxy
:
const express = require('express')
const formatsProxy = require('http-rdf-formats-proxy')
const app = express()
app.get('/proxy', formatsProxy({
// options with their default values:
fetch: require('rdf-fetch-lite')
// Fetch used for the proxy request
// Must implement response.quadStream() returning
// data following RDFJS spec interfaces
formats: require('rdf-formats-common')()
// These formats are used for serialization
// Formats could be taken also from provided fetch
}))
app.server = app.listen(8000)
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'
✓ 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