New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rest-bundle

Package Overview
Dependencies
Maintainers
1
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-bundle

RestBundle is a Javascript base class for a REST resource bundles that can be plugged into a nodejs express application

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
40
-86.97%
Maintainers
1
Weekly downloads
 
Created
Source

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.

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=>...);
    },

Keywords

REST

FAQs

Package last updated on 26 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts