Registry / devops / rest-bundle

rest-bundle

JSON →
library1.1.0jsnpmunverified

RestBundle is a JavaScript base class for creating reusable REST resource bundles that plug into Node.js Express applications. Version 1.1.0 is the current stable release, with a low release cadence. It provides a way to encapsulate related REST endpoints as a class with auto-generated handlers, and integrates with Vue.js 2 and Vuex for state management. Unlike plain Express routers, RestBundle offers a structured approach with resource methods and a state model, making it suitable for developers building modular API services. However, it has dependencies on Vue.js and Vuex, which may not be desirable for non-Vue projects.

npm install rest-bundle
INSTALL
IMPORT
SIG · REST-BUNDLE
R
rest-bundle
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RestBundle
const RestBundle = require('rest-bundle')
import RestBundle from 'rest-bundle'
Package uses CommonJS; ESM import not supported directly as it lacks package.json type: module or ESM entry.
class extends RestBundle
class MyRest extends RestBundle { ... }
class MyRest extends require('rest-bundle') { ... }
Extend RestBundle to define custom REST bundles.
rest-bundle mixins
require('./mixins/rb-api-mixin.js')
import { rbApiMixin } from 'rest-bundle'
Mixins are files within the package, not exported symbols.

Creates a simple REST bundle with GET and POST handlers and binds it to an Express app.

const express = require('express'); const RestBundle = require('rest-bundle'); 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'; } onDie(req, res) { throw new Error('goodbye'); } } const app = express(); var helloRest = new HelloRest('greeting'); helloRest.bindExpress(app); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
gotchaRestBundle requires Vue.js and Vuex even if you only use REST API backend.
fix
Ensure vue and vuex are installed as dependencies.
affects: >=1.0.0
deprecatedThe mixin file path './mixins/rb-about-mixin.js' is deprecated; use 'rest-bundle/mixins/rb-about-mixin.js'.
fix
Update require path to use package name as base.
affects: 1.1.0
breakingVuex store structure changed; state.restBundle.* no longer auto-initializes.
fix
Manually register Vuex module using RestBundle.store. See migration guide.
affects: >=1.1.0
gotcharesourceMethod parameters changed order in v1.1.0: method, path, handler, contentType vs earlier version.
fix
Check calling code for order: (method, path, handler, contentType).
affects: 1.1.0
Errors
Common errors & fixes
Cannot find module 'vue'
Vue.js is a required dependency but not installed.
fix
Run: npm install vue vuex
TypeError: this.resourceMethod is not a function
Calling resourceMethod before super(name, options) is executed.
fix
Ensure super() is called before any methods of the instance.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
expressrequiredFramework for building REST APIs
vueoptionalFrontend framework for UI components
vuexoptionalState management for Vue.js
Agent activity
28 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
rest-bundle — npm install rest-bundle · libregistry