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

catapult_edm

v1.0.6

Published

Express JS addon for writing Web APIs

Downloads

13

Readme

catapult

Catapult is a Web API abstraction tool. The aim of this package is to simplify adding data endpoints to a NodeJS application/server. The generated API endpoints follow RFC 7231. Here is a quick guide of how this works :

For the following example to work, you must have MongoDB running.

Import package

var catapult = require("catapult_edm")

Setup Components

Initialize the RouteMapper and pass the Mongoose Connector provided with the package :

var RouteMapper = new catapult.RouteMapper(
	catapult.MongooseConnector
)

Now add a few Mongoose models to access through REST API

const mongoose = require('mongoose');
mongoose.connect(
    'mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
);

var Pet = { 
	name: String 
}

// resource name will be `cats`
const Cat = mongoose.model('Cat', Pet );

const Dog = mongoose.model('Dog', Pet );

models = {
	Cat,
	Dog
}

Generate API

Add the models to the route mapper.

RouteMapper.add(models.Cat, models.Dog)
var router = RouteMapper.getRouter()

Mount a path for your new endpoints

app.use("/",router)

Web Interface

Once the route mapper is configured and linked to your express server, you can access your data with the following request combinations. Keep in mind that <model name> is the API resource name your data connector returns. The table below will assume that your router is mounted at server root. In Mongoose land, <object id> is the string representation of field _id within your MongoDB object.

|Request Verb | Registered Express Path | Request Body| Result | |--|--| --| --| | POST | /<model name> | JSON string of object to add. { "name" : "Fluffo" } with the models defined above in mind | Newly created object. As a json string. Submit an Array to bulk insert items. ie : [{ "name" : "Fluffo"}] | | GET | /<model name>?query=val | N/A | A list of objects. Query parameters are optional, but can be used to filter results based on a passed string value. | PUT | /<model name>/<object id> | JSON string with object updates | JSON object with success message. | GET | /<model name>/<object id> | N/A | JSON object with the ID of the requested object. null is returned if the object is not found. | GET | /<model name>/find?query=val | N/A | Find an individual record based on query supplied. | DELETE | /<model name>/<object id> | N/A | JSON object with success message, otherwise null

Sample commands with curl:

Get all cats :

curl -XGET 'http://localhost:3000/cats'

Add a new cat record :

curl -XPOST -H "Content-type: application/json" -d '{ "name" : "Fluffo" }' 'http://localhost:3000/cats'

Update a cat record :

curl -XPUT -H "Content-type: application/json" -d '{ "name" : "Fluff" }' 'http://localhost:3000/cats/608d41ca30f954cbf1d11170'