1.0.0 • Published 7 years ago

jsonld-context-link v1.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

jsonld-context-link

Build Status npm version

Express middleware for easy JSON-LD link header handling. The middleware sends the link header for JSON-LD contexts and hosts the contexts.

Usage

The middleware accepts an optional basePath parameter. basePath is used to prefix the context links. The default value for basePath is /. To avoid conflicts it's better define a path which isn't used anywhere else in the application. This would create the middleware, set the basePath to /context/ and attach it to the app:

const jsonldContextLink = require('jsonld-context-link')

const app = express()

const contexts = jsonldContextLink({basePath: '/context/'})

app.use(setLink)

With .setContext a new context is registered with the given key:

contexts.setContext({'@vocab': 'http://schema.org/'}, 'schema')

Now it can be used:

app.use((req, res) => {
  res.setJsonldContext('schema')

  ...
})