Simplify REST API creation and maintentance with re-usable REST bundles. Encapsulate related REST services in a single JavaScript class that extends RestBundle.
Example: Define a REST bundle comprising a single resource (i.e., /greeting/hello)
with handlers for GET and POST:
classHelloRestextendsRestBundle{constructor(name="greeting",options={}){super(name,options);varhandlers=[this.resourceMethod("get","hello",this.getHello,"text/html"),this.resourceMethod("post","hello",this.onDie),];Object.defineProperty(this,"handlers",{value: handlers,});}getHello(req,res){return"hello";}postHello(req,res){thrownewError("goodbye");}}Add HelloRest to a nodejs application:
constHelloRest=require("../test/hello-rest");varhelloRest=newHelloRest("greeting");helloRest.bindExpress(app);Launch web server:
npmstartA RestBundle can be shared for use by others as an npm package.
RestBundle relies on Vue.js for modular web components.
npm run dev- http://localhost:4000/greeting/ui