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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-bits-rest

v0.0.32

Published

Provides a rest api for all schema objects

Downloads

44

Readme

node-bits-rest

node-bits-rest provides a rest api for all schema objects defined by other bits in the loadSchema step.

Install

npm install node-bits-rest --save

or

yarn add node-bits-rest

Configuration

The configuration for the node-bits-rest bit is pretty simple - just the root you want all of the rest endpoints to reside.

nodeBitsRest({prefix: 'api'}),

Example

To complete the circle. Let's say in you include the node-bits-code bit and define an order schema object like:

export const address = {
  street: String,
  city: String,
  state: String,
  country: String,
  postal: String,
};

node-bits-rest will expose a route at /api/address which will accept the following verbs. GET, POST, PUT, DELETE. It will then connect to the database included in the node-bits runtime to expose the following functionality.

GET

  • GET with no parameters will return an array of all documents.
  • GET with an id will return that object if found.

Query, Limit, Order, ...

node-bits-rest exposes the ability to control the results via parameters passed as the query string. It exposes a simple querying syntax for simple needs, but also implements much of OData to handle the complicated scenarios. It will automatically detect which strategy you are using based on the syntax of the parameters and appropriately apply the correct strategy.

  • note on using select - right now only the fields of the root model are supported. If you want to include a 1:M object use the id, if you want to include a M:1 object use the collection name.

Simple

The simple query syntax supports select, expand, orderby, start, max, and filters. Here is a brief description each:

  • select: a comma delimited list of field names to include in the results
  • expand: a comma delimited of related entities to include in the results
  • orderby: a comma delimited list of field name to sort by. To specify the direction use the following format: name:dir, for example: price:desc
  • start: the index of the result set to start from
  • max: the number of records to return in the results
  • filter: any entry in the querystring that is not one of the other key words is treated as part of the where clause. the simple syntax only supports equality. the syntax is name=value, for example: price=5.00

OData

node-bits-rest supports select, expand, orderby, top, skip, and filter from the OData standard. You can read more about this standard on the OData Documentation page.

For filter, node-bits-rest supports the following operators: eq, ne, gt, ge, lt, le, and, or. In addition, it supports the contains, startswith, and endswith functions for filtering.

node-bits-rest will return all queries that use OData in the format {value: [<rows>], @odata.count: <total row count for where clause>}

POST

  • POST expects the model to be in the body. Technically POST should only be used for inserts, but node-bits-rest will look for the existence of an id in the data submitted and appropriately call insert or update.

PUT

  • PUT expects a model in the body with an id. It will call update.

DELETE

  • DELETE expects an id to specified. It will call delete.