# rest-bundle

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

Latest version **1.1.0** (published 2022-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install rest-bundle
pnpm add rest-bundle
yarn add rest-bundle
bun add rest-bundle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-03-26 |
| First published | 2017-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.11.0 |
| Dependencies | 24 |
| Unpacked size | 195 KB |
| Known vulnerabilities | 0 (+29 in 5 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Karl Lew |
| Maintainers | firepick |
| Keywords | REST, resource bundle, express, kinann-org |

## Links

- npm: https://www.npmjs.com/package/rest-bundle
- Repository: https://github.com/kinann-org/rest-bundle
- Issues: https://github.com/kinann-org/rest-bundle/issues
- npm.io page: https://npm.io/package/rest-bundle

## Dependencies (24)

- [ws](https://npm.io/package/ws.md) 3.3.3
- [ejs](https://npm.io/package/ejs.md) ^2.5.6
- [vue](https://npm.io/package/vue.md) ^2.5.2
- [test](https://npm.io/package/test.md) ^0.6.0
- [vuex](https://npm.io/package/vuex.md) ^2.3.1
- [axios](https://npm.io/package/axios.md) ^0.21.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [stylus](https://npm.io/package/stylus.md) ^0.54.5
- [express](https://npm.io/package/express.md) ^4.13.3
- [vuetify](https://npm.io/package/vuetify.md) ^0.17.5
- [winston](https://npm.io/package/winston.md) ^3.1.0
- [vue-axios](https://npm.io/package/vue-axios.md) ^2.1.4
- [bufferutil](https://npm.io/package/bufferutil.md) ^4.0.0
- [vue-loader](https://npm.io/package/vue-loader.md) ^17.0.0
- [vue-router](https://npm.io/package/vue-router.md) ^3.0.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.14.1
- [credentials](https://npm.io/package/credentials.md) ^3.0.2
- [diff-upsert](https://npm.io/package/diff-upsert.md) ^0.1.2
- [file-loader](https://npm.io/package/file-loader.md) ^0.11.1
- [log-instance](https://npm.io/package/log-instance.md) ^0.2.3
- [style-loader](https://npm.io/package/style-loader.md) ^0.17.0
- [stylus-loader](https://npm.io/package/stylus-loader.md) ^3.0.1
- [utf-8-validate](https://npm.io/package/utf-8-validate.md) ^5.0.1
- [vue-template-compiler](https://npm.io/package/vue-template-compiler.md) ^2.5.2

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-03-26
- 1.0.0 — 2022-03-26
- 0.40.21 — 2021-01-06
- 0.40.20 — 2021-01-05
- 0.40.19 — 2020-11-12
- 0.40.18 — 2020-09-05
- 0.40.16 — 2020-08-30
- 0.40.14 — 2020-06-06
- 0.40.13 — 2020-04-10
- 0.40.12 — 2020-03-31
- 0.40.8 — 2019-10-27
- 0.40.7 — 2019-05-31
- 0.40.6 — 2019-05-31
- 0.40.5 — 2019-03-29
- 0.40.4 — 2019-03-27
- … 247 more at https://npm.io/package/rest-bundle/versions

## README

# 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:

```JS
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:

```JS
const HelloRest = require("../test/hello-rest");
var helloRest = new HelloRest("greeting");
helloRest.bindExpress(app);

```

Launch web server:

```JS
npm start
```

A RestBundle can be shared for use by others as an npm package.

### Vue 2
RestBundle relies on [Vue.js](https://vuejs.org/) for modular web components.

1. `npm run dev`
1. http://localhost:4000/greeting/ui


## State Model
RestBundle uses [Vuex](https://vuex.vuejs.org/en/) 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.`<i>service</i>`.`<i>apiName</i>`.`<i>apiModel</i>

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

---
_Source: https://npm.io/package/rest-bundle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
