@koverse/koverse
v2.6.0-alpha-3
Published
Interact with Koverse via NodeJS
Downloads
1
Readme
Koverse
Javascript library for interacting with a Koverse server via node and the browser
Installation
npm install @koverse/koverse --save
Usage
Node
import koverse from '@koverse/koverse'
const koverseApi = koverse({
clientId: 'defaultClient',
clientPassword: 'changeMe',
authenticatorId: 'koverseDefault',
})
koverseApi.services('datasets').find().then(datasets => {
console.log(datasets)
})
Node + Express
If your app uses express, you can choose to mount koverse as a subapp, this will setup a REST api for interacting with the koverse server.
import express from 'express'
import koverse from '@koverse/koverse/lib/express'
import cookieParser from 'cookie-parser'
const app = express()
const koverseApi = koverse({
clientId: 'defaultClient',
clientPassword: 'changeMe',
authenticatorId: 'koverseDefault',
})
const koverseMiddleware = koverseApi.get('koverse').middleware
app.use('/api', koverseApi)
app.use('/login', (req, res) => {
res.send('render login page')
})
app.use(
cookieParser(),
koverseMiddleware.authenticate({ failureRedirect: '/login' }),
(req, res) => {
res.send('render app')
})
Browser
import koverse from '@koverse/koverse/lib/client'
const koverseClient = koverse.createClient({ apiUrl: '/api' })
// authenticate with existing jwt
koverseClient.authenticate()
// authenticate with user credentials
koverseClient.authenticate({
strategy: 'koverse',
email: '[email protected]',
password: 'really-secure-password',
})
// fetch all datasets
koverseClient.service('datasets').find().then(datasets => console.log(datasets))