Socket
Socket
Sign inDemoInstall

@publicodes/rest-api

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@publicodes/rest-api

Publicodes API


Version published
Weekly downloads
42
increased by10.53%
Maintainers
0
Weekly downloads
 
Created
Source

@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 situation
  • GET /rules Returns the list of all your rules
  • GET /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()

// Create middleware with your Engine
const apiRoutes = publicodesAPI(new Engine('coucou: 0'))

// Basic routes usage (/evaluate, /rules, etc.)
router.use(apiRoutes)

// Or use with specific route prefix (/v1/evaluate, /v1/rules, etc.)
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

FAQs

Package last updated on 26 Jul 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