yang-express

2.1.9 • Public • Published

yang-express

YANG model-driven Express framework

Minimalistic web framework leveraging powerful YANG schema expressions according to RFC 6020. Generates dynamic model-driven interfaces with flexible plugin system.

NPM Version NPM Downloads

Installation

$ npm install -g yang-express

The preferred installation is global for easy access to the yang-express utility but can also be used as a dependency module to enable YANG model-driven express app as part of your project.

For development/testing, clone from repo and initialize:

$ git clone https://github.com/corenova/yang-express
$ cd yang-express
$ npm install

Features

  • Robust model-driven routing
  • Hotplug runtime models
  • Dynamic interface generators
  • Hierarchical (deeply nested) data tree
  • Adaptive validations
  • Flexibe RPCs and notifications

Quick Start

$ yang-express example/example-petstore.yang

The above example will import the example-petstore YANG module and start an instance of yang-express listening on port 5000 with restjson feature enabled.

  Usage: yang-express [options] modules...

  Options:
      -p, --port <number>    Run yang-express on <port> (default: 5000)
      -f, --feature <name>   Enable one or more features: (restjson, openapi, etc.)

You can run yang-express inside your own project and it will dynamically import one or more modules and route them using the feature plugins specified.

You can also use it as a library module:

require 'yang-js'
opts =
  port: 5000
  feature: [ 'restjson', 'openapi' ]
  modules: [ 'ietf-yang-library' ]
express = require('yang-express').eval()
express.in('run')
  .invoke opts
  .then  (res) -> console.log "running"
  .catch (err) -> console.error err

For more information on programmatic usage, be sure to take a look at the References listed below.

References

This module is a YANG model-driven data module, which is essentially a composition of the YANG Schema and Control Binding. It is designed to model middleware routing runtime configuration and can be utilized with or without an actual Express instance.

Examples

PetStore is a simple example based on the provided spec sample in the OpenAPI Specification 2.0 project.

$ npm run example:petstore

When the yang-express app runs, it will auto-generate the data model using the example-petstore.yang schema and dynamically route the following endpoints utilizing the restjson dynamic interface generator:

endpoint methods description
/pet CRUMDO operate on the pet collection
/pet/:id RUMDO operate on a specific pet
/pet/:id/:leaf RUMDO operate on a pet's attribute
/pet/:leaf RUMDO bulk operate attributes*

This example runs using the sample data found inside the config directory.

CRUMDO

  • C: CREATE (POST)
  • R: READ (GET)
  • U: UPDATE (PUT)
  • M: MODIFY (PATCH)
  • D: DELETE
  • O: OPTIONS

Alternative API endpoints can be fully-qualified /petstore:pet/... as well as prefix-qualified /ps:pet/.... This is the suggested convention when using multiple models that may have namespace conflict (if mounted together at '/').

Note: Bulk operation on all matching attributes can be used to set a new value for every matching attribute in the collection.

Dynamic Interface Generators

name description
restjson REST/JSON API
openapi OpenAPI/Swagger 2.0 spec
websocket socket.io

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

Apache 2.0

This software is brought to you by Corenova Technologies. We'd love to hear your feedback. Please feel free to reach me at peter@corenova.com anytime with questions, suggestions, etc.

Package Sidebar

Install

npm i yang-express

Weekly Downloads

34

Version

2.1.9

License

Apache-2.0

Unpacked Size

34.5 kB

Total Files

20

Last publish

Collaborators

  • corenova