rest-bundle
RestBundle
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:
class HelloRest extends RestBundle {
constructor(name="greeting",options = {}) {
super(name, options);
var handlers = [
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) { throw new Error("goodbye"); }
}
Add HelloRest to a nodejs application:
const HelloRest = require("../test/hello-rest");
var helloRest = new HelloRest("greeting");
helloRest.bindExpress(app);
Launch web server:
npm start
A RestBundle can be shared for use by others as an npm package.
Vue 2
RestBundle relies on Vue.js for modular web components.
npm run dev- http://localhost:4000/greeting/ui
State Model
RestBundle uses Vuex as its application store. The RestBundle state hierarchy comprises one or more services having one or more API's, each of which has its own apiModel:
state.restBundle.service.apiName.apiModel
Vue components that serve as the primary view of a RestBundle api must define a 'service' property
and include the rb-api-mixin.
mixins: [
require("./mixins/rb-about-mixin.js"),
require("./mixins/rb-api-mixin.js").createMixin("web-socket"),
],
props: {
service: "RbServer",
},
beforeMount(): {
this.apiLoad().then(apiModel=>...).catch(e=>...);
},
Other RestBundle Vue components can become informed of the loading of another
apiModel using the promise returned by onApiModelLoaded(apiName,service):
mixins: [
require("./mixins/rb-about-mixin.js"),
require("./mixins/rb-api-mixin.js").createMixin("some-other-api"),
],
props: {
service: "RbServer",
},
beforeMount(): {
this.onApiModelLoaded("web-socket", "RbServer").then(apiModel=>...).catch(e=>...);
},
Related Packages
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 1.1.0 | ^2.5.2 | MIT | |
| 1.0.0 | ^2.5.2 | MIT | |
| 0.40.21 | ^2.5.2 | MIT | |
| 0.40.20 | ^2.5.2 | MIT | |
| 0.40.19 | ^2.5.2 | MIT | |
| 0.40.18 | ^2.5.2 | MIT | |
| 0.40.16 | ^2.5.2 | MIT | |
| 0.40.14 | ^2.5.2 | MIT | |
| 0.40.13 | ^2.5.2 | MIT | |
| 0.40.12 | ^2.5.2 | MIT | |
| 0.40.8 | ^2.5.2 | MIT | |
| 0.40.7 | ^2.5.2 | MIT | |
| 0.40.6 | ^2.5.2 | MIT | |
| 0.40.5 | ^2.5.2 | MIT | |
| 0.40.4 | ^2.5.2 | MIT | |
| 0.40.3 | ^2.5.2 | MIT | |
| 0.40.2 | ^2.5.2 | MIT | |
| 0.40.0 | ^2.5.2 | MIT | |
| 0.39.4 | ^2.5.2 | MIT | |
| 0.39.2 | ^2.5.2 | MIT | |
| 0.39.1 | ^2.5.2 | MIT | |
| 0.39.0 | ^2.5.2 | MIT | |
| 0.38.3 | ^2.5.2 | MIT | |
| 0.38.2 | ^2.5.2 | MIT | |
| 0.38.1 | ^2.5.2 | MIT | |
| 0.38.0 | ^2.5.2 | MIT | |
| 0.37.5 | ^2.5.2 | MIT | |
| 0.37.4 | ^2.5.2 | MIT | |
| 0.37.3 | ^2.5.2 | MIT | |
| 0.37.2 | ^2.5.2 | MIT |
Showing the latest 30 of 262. See every release on npm