Registry / devops / bedrock-rest

bedrock-rest

JSON →
library3.0.0jsnpmunverified

A Bedrock module that adds helpers for REST support, including resource handlers, ID parameter validation, and content negotiation for JSON, JSON-LD, and HTML requests. Version 3.0.0 is the latest stable release, compatible with Bedrock 1.x-3.x and Node.js >=8. It provides middleware like makeResourceHandler and idParam for express-based applications. Differentiators include tight integration with the Bedrock ecosystem and automatic type negotiation.

npm install bedrock-rest
INSTALL
IMPORT
SIG · BEDROCK-REST
B
bedrock-rest
devopsjavascriptv3.0.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.

default
const brRest = require('bedrock-rest');
import brRest from 'bedrock-rest'; // ESM not supported
Package uses CommonJS; no ESM or TypeScript types available.
idParam
const { idParam } = require('bedrock-rest');
import { idParam } from 'bedrock-rest'; // ESM not supported
Destructured import from CommonJS module.
makeResourceHandler
const { makeResourceHandler } = require('bedrock-rest');
import { makeResourceHandler } from 'bedrock-rest'; // ESM not supported
Alias linkedDataHandler also available.
when
const { when } = require('bedrock-rest');
const when = require('bedrock-rest').when; // Works but verbose
when.prefers.jsonld and when.prefers.ld middleware.

Sets up a REST endpoint with Bedrock-Express using idParam and makeResourceHandler.

const bedrock = require('bedrock'); const brRest = require('bedrock-rest'); bedrock.events.on('bedrock-express.init', function(app) { app.param('identity', brRest.idParam); }); bedrock.events.on('bedrock-express.configure.routes', function(app) { const idPath = bedrock.config.identity.basePath + '/:identity'; app.get(idPath + '/dashboard', brRest.makeResourceHandler()); app.get(idPath + '/items', brRest.makeResourceHandler({ get: function(req, res, callback) { callback(null, { items: [] }); } })); }); bedrock.start();
Debug
Known issues
gotchamakeResourceHandler() without options object will cause errors.
fix
Always pass an options object, e.g., makeResourceHandler({}) or with get property.
affects: >=3.0.0
gotchaidParam expects a 'bedrock-express' app; not compatible with raw Express without setup.
fix
Use with bedrock-express and the 'bedrock-express.init' event.
affects: >=3.0.0
deprecatedlinkedDataHandler is an alias for makeResourceHandler and may be removed in future.
fix
Use makeResourceHandler directly.
affects: >=3.0.0
gotchaContent negotiation defaults: JSON enabled, HTML defaults to 'route'.
fix
Set options.json false or options.html false if not needed.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'bedrock-rest'
Missing npm install or incorrect path.
fix
Run: npm install bedrock-rest
TypeError: brRest.idParam is not a function
Importing incorrectly (e.g., default import with ESM).
fix
Use require('bedrock-rest') and destructure: const { idParam } = require('bedrock-rest');
Error: listen EADDRINUSE :::80
Port already in use; common when running multiple instances.
fix
Change port in config or kill existing process: lsof -ti:80 | xargs kill
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
bedrockrequiredCore framework dependency; required for events and config.
bedrock-validationoptionalUsed for optional validation in makeResourceHandler options.
Agent activity
9 hits · last 30 days
node
8
Resources
bedrock-rest — npm install bedrock-rest · libregistry