npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@node-in-layers/rest-api

v1.1.2

Published

A Rest API implementation with a Node In Layers system.

Readme

REST API - A Node In Layers Package

This package contains useful out-of-the-box tools for building REST APIS rapidly.

It includes boilerplate code for starting a modern production JSON REST API Express server, as well as code for making model based apis, with minimal boilerplate.

How to Install

npm install @node-in-layers/rest-api@latest

How To Use

There are three main components of this express package.

  • Model Based Express Controller
  • Model Based Router Controller
  • Custom Layer - express

Model Based Express Controller

A model based express controller is an express controller that can wrap around a model from the functional-models model system. It connects to the CRUDS functionality inside @node-in-layers/db for you (create, retrieve, update, delete, search). This pairs very well with the model based express router, although is not required.

Model Based Express Router

The model based express router is an express router that provides routing to a CRUDS controller. This handles all the pathing and takes this format:

Create:

PUT: /namespace/my-model-name

Retrieve:

GET: /namespace/my-model-name/:id

Update:

PUT: /namespace/my-model-name/:id

Delete:

DELETE: /namespace/my-model-name/:id

Search:

POST: /namespace/my-model-name

A Quick note on search

The search endpoint is a POST instead of a GET because it uses a JSON body for the search. The JSON body is a JSONified version of the OrmSearch object from functional-models.

Url Prefix

You can append a prefix to the url by adding it as an argument to the router. This can be useful for adding a service level name before all of your models.

Custom Layer - "express"

This package adds a custom layer called "express". This layer is intended to be a composite layer with the entries layer. This is for systems that use express as the final top layer. One example would be a REST API Backend. This custom layer, adds a number of functions that are useful for setting up an express server. (Setting routes, adding middleware, starting the server with listen).

To add your own routes and middleware you need to create a express layer (such as a file named express.ts that has a create() function in it).

How To Use

In order to use the express layer, you need to add it as a composite layer inside the configuration file, as well as this app itself.

// Example config.dev.mjs
import { CoreNamespace } from '@node-in-layers/core/index.js'
import { DataNamespace } from '@node-in-layers/data/index.js'
import { RestApiNamespace } from '@node-in-layers/rest-api/index.js'
import { peteSdkLogger } from './dist/logging.js'

const core = {
  apps: await Promise.all([
    import(`@node-in-layers/data/index.js`),
    // Import here
    import(`@node-in-layers/rest-api/express/index.js`),
  ]),
  // NOTE: The composite layer with entries.
  layerOrder: ['services', 'features', ['entries', 'express']],
  logging: {
    logLevel: 'debug',
    logFormat: 'full',
  },
  modelFactory: '@node-in-layers/data',
  modelCruds: true,
}

const data = {
  databases: {
    default: {
      datastoreType: 'memory',
    },
  },
}

const express = {
  port: 8000,
  urlPrefix: '/my-service/',
}

export default () => ({
  environment: 'dev-low',
  systemName: 'my-system',
  [CoreNamespace.root]: core,
  [DataNamespace.root]: data,
  [RestApiNamespace.express]: express,
})

Model CRUDS

In order to CRUDS functionality to the REST interface you need to create this express layer in your app, and use the express functions provided by this library. A useful function called expressModels can be used that automatically adds all model CRUDS from your namespace.

Example Use

We want to create a model and provide CRUDS routes to it. The easiest way to do this is to create our There is a helper method on the custom express layer called #addModel() that makes this really easy.

// /src/your-app/express.ts
import { FeaturesContext } from '@node-in-layers/core/index.js'
import {
  ExpressContext,
  expressModels,
} from '@node-in-layers/rest-api/index.js'

const express = {
  create: (context: ExpressContext & FeaturesContext) => {
    // Automatically adds all cruds models feature functions to express.
    expressModels('your-namespace')(context)
  },
}

export { express }

Troubleshooting

Model endpoints aren't working

Make sure that your app has the following layers (even if they are only an empty create):

  1. Services - Can be empty
  2. Features - Can be empty
  3. Express - See above
  4. modelCruds is set to true - See core configurations.