GitHub - corenova/yang-express: YANG model-driven Express framework (original) (raw)

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 theyang-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

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 withrestjson 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 thefeature 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 andControl 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 theOpenAPI Specification 2.0project.

$ npm run example:petstore

When the yang-express app runs, it will auto-generate the data model using the example-petstore.yangschema and dynamically route the following endpoints utilizing therestjson 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 thesample data found inside theconfig directory.

CRUMDO

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:

License

Apache 2.0

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