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

antarest

v0.3.0

Published

Easy to build REST microservices

Readme

Antarest

Simple REST factory with mongoosejs. Antarest will simply generate your GET, POST, PATCH, DELETE rest endpoint and other functionality without pain.

v0.1.0:

  • Only support mongoosejs, highly-coupled inside Antarest.
  • PUT not currently supported

Installation

npm install antarest

Usage

antarest(MONGODB_URI, MONGOOSE_OPTIONS, ARRAY_OF_SERVICE_OBJ, OPTIONS)

MONGODB_URI: Your database URI

MONGOOSE_OPTIONS: mongoose.connect() object config

ARRAY_OF_SERVICE_OBJ: Your service object

OPTIONS: Antarest option

[
  { 
    path: '/cat', // path used as endpoint
    model: {
      name: 'Cat', // model name
      schema: Cat, // mongoose schema
      collection: 'cats' // collections name for model
    }
  }
]

Above usage will return express object and can be directly used with app.use()

var myRest = antarest(MONGODB_URI, MONGOOSE_OPTIONS, ARRAY_OF_SERVICE_OBJ)

app.use(myRest)

Example

Simple usage

var express = require('express')
var mongoose = require('mongoose')
var bodyParser = require('body-parser')

var antarest = require('antarest')

var app = express()

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

var Cat = new mongoose.Schema({ name: String, weight: Number, birth: Date })

app.use(
  antarest(
    'mongodb://localhost:27017/animals', 
    { promiseLibrary: global.Promise }, 
    [
      { 
        path: '/cat', 
        model: {
          name: 'Cat',
          schema: Cat,
          collection: 'cats' 
        }
      }
    ]
  )
)

app.listen(6969)

Every antarest instantiation will generate this endpoint for you:

localhost:6969/cat/ - GET

Endpoint for get all doc from database.

Example, return all docs:

GET localhost:6969/cat

result:

{
  "status": 200,
  "payload": [      
    {
      "_id": "5a98fb2dde626515810b8807",
      "name": "Thomas The Cat",
      "weight": 2,
      "birth": "2018-01-01T00:00:00.000Z",
      "__v": 0
    },
    {
      "_id": "5a98fb24de626515810b8806",
      "name": "Fluff The Cat",
      "weight": 5,
      "birth": "2016-12-01T00:00:00.000Z",
      "__v": 0
    },
    {
      "_id": "5a9908746df866266c758216",
      "name": "Muff The Cat",
      "weight": 2,
      "birth": "2016-12-01T00:00:00.000Z",
      "__v": 0
    }
  ],
  "msg": "Return all payload that match filter",
  "query": {}
}

Example with query string:

GET localhost:6969/cat?name=Thomas+The+Cat

Result:

{
  "status": 200,
  "payload": [      
    {
      "_id": "5a98fb2dde626515810b8807",
      "name": "Thomas The Cat",
      "weight": 2,
      "birth": 2018-01-01T00:00:00.000Z,
      "__v": 0
    }
  ],
  "msg": "Return all payload that match filter",
  "query": {
    "name": "Thomas The Cat"
  }
}

For now, the query key must be same with the field in the mongoose schema.

Query string only capable to do equal operator. For more complex operation refer to /search

localhost:6969/cat/search - POST

Endpoint to get all docs given conditions in body request.

Request body must be in 'application/json' format. Set 'Content-Type' header to application/json

Content-Type: application/json

Example:

POST localhost:6969/cat
Content-Type: application/json
{ "name": { "$eq": "Thomas The Cat" } }

The body request object refer to this mongodb documentation https://docs.mongodb.com/manual/reference/operator/query/. You can build your complex query, including limit and grouping, based on the documentation and send them as json to get your docs properly. Make sure that your conditions query match with your MongoDB version running.

Result:

{
  "status": 200,
  "payload": [      
    {
      "_id": "5a98fb2dde626515810b8807",
      "name": "Thomas The Cat",
      "weight": 2,
      "birth": 2018-01-01T00:00:00.000Z,
      "__v": 0
    }
  ],
  "msg": "Return all payload that match filter",
  "query": {
      "name": {
        "$eq": "Thomas The Cat"
      }
    }
}

localhost:6969/cat/aggregate - POST

Endpoint to make aggregation operation.

Request body must be in 'application/json' format. Set 'Content-Type' header to application/json

Content-Type: application/json

Example:

POST localhost:6969/cat
Content-Type: application/json
[
	{ 
		"$match": {
			"weight": {"$gt": 3}
		}
	},	
	{
		"$group": { 
      "_id": null, 
      "fat_cat": {"$sum": 1}
    }
	}
]

The body request aggregation conditions refer to this mongodb documentation https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/. You can build your complex aggregation pipeline based on the documentation and send them as json to get your docs properly. Make sure that your aggregation pipeline conditions match with your MongoDB version running.

Result:

{
  "status": 200,
  "payload": [
    {
      "_id": "null",
      "fat_cat": 1
    }
  ],
  "msg": "Return all payload that match filter",
  "query": [
    { 
      "$match": {
        "weight": {"$gt": 3}
      }
    },	
    {
      "$group": { 
        "_id": null, 
        "fat_cat": {"$sum": 1}
      }
    }
  ]
}

^ using MongoDB v3.2

localhost:6969/cat/ - POST

Create new doc.

Example:

POST localhost:6969/cat
{
  "name": "Puff The Cat",
  "weight": 2,
  "birth": "2018-01-01T00:00:00.000Z"
}

Result:

{
    "status": 201,
    "payload": {
        "name": "Puff The Cat",
        "weight": 2,
        "birth": "2018-01-01T00:00:00.000Z",
        "_id": "5a9daff5b3529a1b416137c2",
        "__v": 0
    },
    "msg": "Created"
}

localhost:6969/cat/ - PATCH

Patch single or multiple docs given conditions

Example:

PATCH localhost:6969/cat

conditions

{
  "conditions": { "_id": { "$eq": "5a9908746df866266c758216" } },
  "patch": { "weight": 3 }
}

Result:

{
  "status": 200,
  "payload": [
    {
      "_id": "5a9908746df866266c758216",
      "name": "Muff The Cat",
      "weight": 3,
      "birth": "2016-12-01T00:00:00.000Z",
      "__v": 0
    }
  ],
  "msg": "All docs updated",
  "query": {
    "_id": "5a9908746df866266c758216"
  }
}

Conditions property on body refer to MongoDB query https://docs.mongodb.com/manual/reference/operator/query/

WARNING: It is important for you to make sure you pass your conditions. If you pass an empty object all docs will be updated.

localhost:6969/cat/ - DELETE

Delete single or multiple docs given conditions

Example:

DELETE localhost:6969/cat

conditions

{
  "conditions": { "weight": { "$gt": 3 } }  
}

Result:

{
  "status": 200,
  "payload": [
    {
      "_id": "5a9908746df866266c758216",
      "name": "Fluff The Cat",
      "weight": 5,
      "birth": "2016-12-01T00:00:00.000Z",
      "__v": 0
    }
  ],
  "msg": "All docs match deleted",
  "query": {
    "weight": {
      "$gt": 3
    }
  }
}

WARNING: It is important for you to make sure you pass your conditions. If you pass an empty object all docs will be deleted.

Options

NotFoundHandler: false, Add 404 handler

Multiple Antarest Use

You can using antarest with multiple mongoose connection as you want.

Example:

...
var Cat = new mongoose.Schema({ name: String, weight: Number, birth: Date })
var Dog = new mongoose.Schema({ name: String, weight: Number, birth: Date })

app.use(
  antarest(
    'mongodb://localhost:27017/cats', 
    { promiseLibrary: global.Promise }, 
    [
      { 
        path: '/cat', 
        model: {
          name: 'Cat',
          schema: Cat,
          collection: 'cats' 
        }
      }
    ]
  )
)

app.use(
  antarest(
    'mongodb://localhost:27017/dogs', 
    { promiseLibrary: global.Promise }, 
    [
      { 
        path: '/dog', 
        model: {
          name: 'Dog',
          schema: Dog,
          collection: 'dogs'
        }
      }
    ], 
    { NotFoundHandler: true }
  )
)
...

Antarest will separate the connection so you will use all your mongoose database connection.

License

MIT