0.4.5 • Published 19 days ago

@hydrofoil/labyrinth v0.4.5

Weekly downloads
577
License
-
Repository
-
Last release
19 days ago

@hydrofoil/labyrinth

Labyrinth is an opinionated, batteries-included middleware for setting up a Hydra API with ease in data-centric manner.

It uses hydra-box internally and extends it to provide ready to use building blocks for rapid RDF-base API development.

Installation

npm i --save @hydrofoil/labyrinth

Setting up

Labyrinth exports an async factory function which creates an express handler.

import express from 'express'
import * as path from 'path'
import { hydraBox } from '@hydrofoil/labyrinth'

// base path to load JavaScript code referenced in Api Documentation
const codePath = path.join(__dirname, 'lib')
// path to load the Api Documentation from Turtle files
const apiPath = path.join(__dirname, 'hydra')
// base resource namespace
const baseUri = 'http://example.com/'

async function main() {
  const app = express()
    
  app.use(await hydraBox({
    codePath,
    apiPath,
    baseUri,
    path,        // (optional) ApiDocumentation URL path
    defaultBase, // (optional) base URI to parse API Documentation
    loader,      // (optional) hydra-box resource loader
    // SPARQL endpoint
    sparql: {
      endpointUrl, // Query
      updateUrl,   // (optional) Update 
      storeUrl,    // (optional) Graph Protocol,
      user,        // (optional) endpoint user name
      password     // (optional) endpoint password
    },
    options: {
      collection: {
        pageSize   // (optional) default page size of paged collections   
      }  
    },
    errorMappers: [] // (optional) map errors into problem+json
    middleware: {    // (optional) hydra-box middleware (arrays or function)
      operations,    // runs before final operation is selected. modify `req.hydra.operations` here
      resource,      // runs before operation is invoked. modify `req.hydra.resource` here
    }
  }))
  
  app.listen(8080)
}

main()

Features

  • Generic handlers for getting individual resources
    • Eager loading linked resources
    • Resource preprocessor for custom resource logic before handler
  • Generic hydra:Collection handler
    • Create any collection using hydra:manages block
    • Custom filtering
    • Ordering using property paths
    • Paging using hydra:pageIndex
  • Secured using JWT tokens
    • Permission-based restrictions to operations
    • Restricting select properties or entire classes
  • Error handling using Problem Details for HTTP APIs (RFC 7807)

Difference from hydra-box

In contrast to hydra-box it also makes some limiting assumptions:

  1. All resources are stored in triple store in named graph-per resource fashion
  2. Labyrinth provides its own loader which does SPARQL CONSTRUCT query to load said resources
    • Another loader can be used
  3. At the moment ApiDocumentation is only loaded from the filesystem. In the future loading from other sources may be added
0.4.5

19 days ago

0.13.13

1 year ago

0.4.4

1 year ago

0.13.6

2 years ago

0.13.7

2 years ago

0.13.8

2 years ago

0.13.9

2 years ago

0.13.12

2 years ago

0.13.11

2 years ago

0.13.10

2 years ago

0.13.4

2 years ago

0.13.5

2 years ago

0.4.3

2 years ago

0.13.0

2 years ago

0.11.2

2 years ago

0.13.1

2 years ago

0.11.3

2 years ago

0.13.2

2 years ago

0.13.3

2 years ago

0.12.0

2 years ago

0.4.2

2 years ago

0.11.0

2 years ago

0.11.1

2 years ago

0.10.3

2 years ago

0.10.4

2 years ago

0.10.5

2 years ago

0.10.6

2 years ago

0.10.7

2 years ago

0.10.8

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.10.0

2 years ago

0.8.4

2 years ago

0.10.0-alpha.2

2 years ago

0.10.0-alpha.1

2 years ago

0.10.0-alpha.0

2 years ago

0.9.0

2 years ago

0.9.1

2 years ago

0.8.3

2 years ago

0.7.5

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.7.4

2 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.3

2 years ago

0.7.0

3 years ago

0.6.6

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.15-next.0

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago