Skip to the content.
SCRUD

scrud NPM version js-standard-style

SCRUD API server, fast, light, capable

what is SCRUD

It’s just CRUD with a search action included in the package.

Every resource has corresponding SCRUD actions which are expressed in the HTTP methods and path (resource ids and query params).

what is this module

who is it for

install

$ npm install --save scrud

usage

const scrud = require('scrud')
const config = require('./secrets.json')

async function main () {
  const memberHandler = {
    update: (req, res) => scrud.sendData(res, 'not updated, goteem'),
    delete: (req, res) => scrud.sendErr(res, new Error('Resource cannot be deleted')),
    beforeQuery: {
      search: (req, res) => {
        delete req.params.someProperty
        return Promise.resolve()
      }
    },
    beforeSend: {
      read: (req, res, data) => {
        data.meaningOfLife = 42
        return Promise.resolve(data)
      }
    }
  }

  scrud.register('member', memberHandler)
  await scrud.start(config)
}

api

scrud.register(name, handlers)

Returns: Promise which with resolves with resource object

Arguments:

scrud.start(options)

Set global options and start API server

Returns: Promise which with resolves with http.Server

Arguments:

helper functions (used internally but exported as a courtesy)

generic helpers

database action helpers

scrud helpers

get-scrud - A handy client for SCRUD APIs, backed by axios

license

MIT © Andrew Carpenter