Socket
Socket
Sign inDemoInstall

@kopflos-cms/core

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kopflos-cms/core

Hydra middleware for web APIs


Version published
Weekly downloads
35
decreased by-78.12%
Maintainers
2
Weekly downloads
 
Created
Source

@kopflos-cms/core

Hydra is a machine readable description for APIs. Kopflos extends the API description with links to the actual code, which provides the API. Kopflos will use such an API description to create an express middleware which provides the API and dynamically loads the required code for it.

Usage

Application

@kopflos-cms/core uses an object that implements the RDF/JS Store interface to read resources and find types of resources to identify matching operations. The resource is read using the IRI as named graph filter.

Here an example for a store on the local file system using rdf-store-fs:

import FlatMultiFileStore from 'rdf-store-fs/FlatMultiFileStore.js'

const store = new FlatMultiFileStore({
  baseIRI: 'http://localhost:9000/',
  path: 'store'
})

An Api object contains the dataset of the API documentation, where to find it and where to find the code. The static method .fromFile reads the dataset from the given file and creates an Api object with the given options.

import rdf from '@zazuko/env-node'

const api = await Api.fromFile('api.ttl', {
  factory: rdf,
  path: '/api',
  codePath: __dirname
})

The factory parameter is required, and must be an RDF/JS Environment, providing the following factories compatible with the following:

Once both objects are created, the middleware can be used:

const app = express()
app.use(hydraBox(api, store))
app.listen(9000)

Operation

The operations must implement a Express routing handler interface ((req, res, next) => {}). @kopflos-cms/core adds the @rdfjs/express-handler to handle incoming and outgoing RDF data. For GET requests with a matching IRI Template, the .dataset() and .quadStream() as defined by express-handler are also available to read the given variables. Additionally, there is a hydra property assigned to req that contains more data about the request:

  req.hydra = {
    // Api object given as argument to the middleware
    api,
 
    // RDF/JS Store object given as argument to the middleware
    store,
 
    // requested URL as RDF/JS NamedNode
    term,
    
    // the selected hydra:Operation as Graph Pointer
    operation,

    // resource this request is about
    // This can be the requested URL for the case that a class operation is called.
    // For the case that a property operation is called, this is the subject of the triple used to link to the property.
    resource: {

      // IRI of the resource as RDF/JS NamedNode
      term,

      // content of the resource read from the store as RDF/JS Dataset 
      dataset,

      // rdf:types of the resource as @rdfjs/term-set
      types
    }
  }

FAQs

Package last updated on 22 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc