digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

is content negotiation automatically supported for schema.org but not for other servers? #386

Closed satra closed 4 years ago

satra commented 4 years ago

We are observing some differences in retrieving jsonld documents between schema.org and our server. We would like to know if we should be implementing content negotiation differently on our server.

on our server this: curl -H "Accept: application/ld+json" https://schema.repronim.org/rl/activities/AdultSelfReport works and without the accept header will return an html landing page. we also support adding .jsonld at the end of the url similar to schema.org (https://schema.org/docs/developers.html).

does jsonld.js treat schema.org specially?

here are some details. please click on the triangles to expand.

content negotiation on schema.org ```node > jsonld.expand('https://schema.org/option').then((resp) => { console.log(resp);}) Promise { } > [ { '@id': 'http://schema.org/option', '@type': [ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property' ], 'http://www.w3.org/2000/01/rdf-schema#comment': [ [Object] ], 'http://www.w3.org/2000/01/rdf-schema#label': [ [Object] ], 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf': [ [Object] ], 'http://schema.org/domainIncludes': [ [Object] ], 'http://schema.org/rangeIncludes': [ [Object], [Object] ], 'http://schema.org/supersededBy': [ [Object] ] } ] ```
content negotiation fails on our server ```node > jsonld.expand('https://schema.repronim.org/rl/activities/AdultSelfReport').then((resp) => { console.log(resp);}) Promise { } > (node:34636) UnhandledPromiseRejectionWarning: jsonld.LoadDocumentError: Could not retrieve a JSON-LD document from the URL. at Function.jsonld.get (/Users/satra/Downloads/hrv-quick/node_modules/jsonld/lib/jsonld.js:888:11) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Function.jsonld.expand (/Users/satra/Downloads/hrv-quick/node_modules/jsonld/lib/jsonld.js:309:23) (node:34636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3) ```
but works on our server when we make it explicit ```node > jsonld.expand('https://schema.repronim.org/rl/activities/AdultSelfReport.jsonld').then((resp) => { console.log(resp);}) Promise { } > [ { '@id': 'https://schema.repronim.org/rl/activities/AdultSelfReport_schema', '@type': [ 'https://schema.repronim.org/rl/schemas/Activity' ], 'https://schema.repronim.org/rl/terms/preamble': [ [Object] ], 'http://schema.org/description': [ [Object] ], 'http://schema.org/schemaVersion': [ [Object] ], 'http://schema.org/version': [ [Object] ], 'http://www.w3.org/2004/02/skos/core#altLabel': [ [Object] ], 'http://www.w3.org/2004/02/skos/core#prefLabel': [ [Object] ], 'https://schema.repronim.org/rl/terms/order': [ [Object] ], 'https://schema.repronim.org/rl/terms/shuffle': [ [Object] ] } ] ```
gkellogg commented 4 years ago

No special treatment for schema.org, in fact, they complain about needing to respond to the Accept header to redirect.

Make sure your server is properly set up to honor the content-negotiation on Accept: application/ld+json. When I run the following:

curl -H 'Accept: application/ld+json' https://schema.repronim.ortivities/AdultSelfReport

It returns JSON-LD. Perhaps you're getting other headers that are affecting the way you send results. Can't tell on this end. Many services will send several Accept types, and one of those could be affecting what you return. Best examine your log files. I see similar issues running it through my own service at http://rdf.greggkellogg.net/distiller.

satra commented 4 years ago

thank @gkellogg - will keep debugging at our end. will close this for now, and will post back if we find a solution (or the actual problem).