@publicodes/api
This package allows you to create a REST API, which follows OpenAPI 3.0 specifications, from your Publicodes rules.
It consists of Koa middleware that adds routes to your router:
POST
/evaluate
Evaluate one or more expressions with a given situationGET
/rules
Returns the list of all your rulesGET
/rules/{rule}
Returns a specific rule
Installation
npm install @publicodes/api
Utilisation
import Router from '@koa/router'
import Koa from 'koa'
import Engine from 'publicodes'
import { koaMiddleware as publicodesAPI } from '@publicodes/api'
const app = new Koa()
const router = new Router()
const apiRoutes = publicodesAPI(new Engine('coucou: 0'))
router.use(apiRoutes)
router.use('/v1', apiRoutes)
app.use(router.routes()).listen(3000)
A complete example file is in the sources if needed : example.ts.
Documentation
Projets phares