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

restless-api

v0.0.1

Published

(RESTful) APIs for the highly impatient: Just write a public-facing API spec in JSON, and let this do the Express routing for you. Not as cool as Swagger but a LOT simpler.

Downloads

3

Readme

restless api: RESTful APIs for the highly impatient

Under development

  • restless-api takes a JSON spec of your APIs like you would send your user (no code inside it) and handles all the Express routing

  • the goal has been to be as-simple-as-possible at all decision points, but there is support for model/controller breakdown and dependency injection if you want it

  • Available on NPM @ https://www.npmjs.org/package/restless-api

Example: see Node Annotator Store backend

Quick start

  • Add restless-api to your project: npm install --save restless-api
  • In your app file, call restless-api with JSON having two keys
    • links: user-facing API spec (NO CODE, literally ready to send your user)
    • nouns: contains a reference to a module (or optionally a controller and model) for each noun

Example:

(Run node examples/app.js to try it!)

var restlessApi = require('../index.js');
var apiRouter = restlessApi({
    "links": {
        /* each key in 'links' is a REST noun from 'nouns' at end */
        "user": { 
             "index": {
                "url": "/users",
                "method": "GET",
                "desc": "Show a list of users"
            },
            "read": {
                "url": "/users/:id",
                "method": "GET",
                "desc": "Get a user by ID"
            },
            "create": {
                "url": "/users",
                "method": "POST",
                "desc": "Add a new user"
            },
            "update": {
                "url": "/users/:id",
                "method": "PUT/POST",
                "desc": "Update an existing user with ID=:id" 
             }
             /* each key in a given noun denotes a REST endpoint (url+method)
                and will be routed to the callback in the noun module associated with the same key.
                
                for example, 'update' above will invoke the function 'update' in 'lib/users.js' - 
                because that is the module associated with the noun in 'nouns' below 
             */
        }
    },
    "nouns": {
    
         "user": {
            "model": require("./lib/userModel.js"),
            "controller": require("./lib/userController.js")
         }
    
    /*
       - Addl nouns:
         You can add more nouns here

       - Nouns can be specified with a single file:
            "products": require("./lib/products.js")

       - Or you can specify a model and controller separately, e.g.:
         "products": {
            "model": require("./lib/productModel.js"),
            "controller": require("./lib/productController.js")
         }
        -  The callbacks in the 'controller' module will be invoked with the model dependency injected
     */
    }  
});
  • In your app file you use the router returned as normal:
// The routes above are relative; restless-api returns an express.Router object
// which you can mount wherever you want
// e.g. "/api":
express.use("/api", apiRouter);

express.listen(3000);
console.log("Listening on port 3000!");
  • And then create modules for each noun, e.g. ./lib/userController.js might be:
module.exports =  {
           index: function index(req, res, User) {
           //      ...
           },
           read: function read(req. res, User) {
           //       ...
           },
//...
};
  • Where the 3rd user argument is the user model (this example used one unified model+controller for user noun, but if they were separate this would be the controller and it would get the model ref there)