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

rest-api-request

v0.6.1

Published

Library for easy communication with the API server

Readme

Rest-api-request

npm package

Tutorials NPM version Dependency Status devDependency Status

Install

npm install rest-api-request --save

Full example

I do not have more time for write documentation today. Look at tests folder for more examples. The project is in active development. Architecture is not yet determined. Do not use it in production projects.

I'll update the documentation and write tests once the architecture will be determined definitively.

'use strict'

const async = require('async')

// Request options
const options = {
  baseUrl: 'http://localhost:3001'
}

const API = require('rest-api-request')(options)

// Define model

const Model = API.model('platform')

// Testing method .getUrl()

let indexUrl = Model.find({name: 'testname'}).getUrl()
let showUrl = Model.findOne({name: 'testname'}).getUrl()
let createUrl = Model.create().getUrl()
let updateUrl = Model.findOne({name: 'testname'}).getUrl()
let deleteUrl = Model.findOne({name: 'testname'}).getUrl()

console.log('GET %s', indexUrl)
// Response: GET /platform/index?where[0][name]=testname

console.log('GET %s', showUrl)
// Response: GET /platform/show?where[0][name]=testname

console.log('POST %s', createUrl)
// Response: POST /platform/create

console.log('PUT %s', updateUrl)
// Response: PUT /platform/show?where[0][name]=testname

console.log('DELETE %s', deleteUrl)
// Response: DELETE /platform/show?where[0][name]=testname

// Testing CRUD with real API server

async.series({
  create: (callback) => {
    Model.create({name: 'testname'}).exec()
    .then(model => callback(null, model))
    .catch(callback)
  },
  find: (callback) => {
    Model.find({name: 'testname'}).exec()
    .then(models => callback(null, models))
    .catch(callback)
  },
  update: (callback) => {
    Model.update({name: 'testname'}, {name: 'newname'}).exec()
    .then(model => callback(null, model))
    .catch(callback)
  },
  findOne: (callback) => {
    Model.findOne({name: 'newname'}).exec()
    .then(model => callback(null, model))
    .catch(callback)
  },
  delete: (callback) => {
    Model.delete({name: 'newname'}).exec()
    .then(model => callback(null, model))
    .catch(callback)
  }
}, (err, response) => {
  if (err) return console.log('Error: ', err)
  console.log(response)
})

/*
  Response:

  {
    create: {
      _id: '56b60f6605e4d1667563c50c',
      name: 'testname',
    },

    find: [
      {
        _id: '56b60f6605e4d1667563c50c',
        name: 'testname',
      }
    ],

    update: {
      _id: '56b60f6605e4d1667563c50c',
      name: 'newname',
    },

    findOne: {
      _id: '56b60f6605e4d1667563c50c',
      name: 'newname',
    },

    delete: {
      _id: '56b60f6605e4d1667563c50c',
      name: 'newname',
    }
  }
 */

Configure

Options are the same as for the package request because it is used in the method .exec() under the hood.

const options = {
  baseUrl: 'http://localhost:3001'
}

const API = require('rest-api-request')(options)

const User = API.model('user')

Build url string without request

If you do not want to use the package request for api calls, you can get the URL address as a string, without sending a request to the API server.

let query = User.find({name: 'user1'}).select('name type').limit(2).skip(10)
let url = query.getUrl()

Now variable url contains the string:

/user/index?where[0][name]=user1&select[0]=name&select[1]=type&limit=2&skip=10

Error handlers

let query = User.findOne({name: 'user1'}).select('name type').exec()

query.catch(error => console.log(error))

/* 
  Response:
  { 
    error: { 
      message: "Error text from api server" 
    } 
  }
*/