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 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
$ 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.
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.
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.
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.
name | description |
---|---|
restjson | REST/JSON API |
openapi | OpenAPI/Swagger 2.0 spec |
websocket | socket.io |
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
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.