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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cloudifyjs/restful

v0.1.4

Published

FaaS agnostic restful microframework

Readme

@cloudifyjs/restful

CircleCI npm npm dependencies Status devDependencies Status codecov Greenkeeper badge Known Vulnerabilities

The @cloudifyjs/restful is a microframework that aims to make the development of RESTful Web Services on top of FaaS free from cloud providers implementations. Develop first and choose the cloud provider later!

Install

Install with npm:

npm install @cloudifyjs/restful --save

Install with yarn:

yarn add @cloudifyjs/restful

Features

  • Provides cloud agnostic wrappers for RESTful Web Services.
    • Built-in request handlers (aws and google).
  • Minimal configuration.
  • Supports HATEOAS principle.
  • Supports request validation with @hapijs/joi.
  • Supports RESTful principle.
  • Extensible: Plug you own hypster cloud provider as you need.
  • async/await oriented / No Callback Hell.

Examples

Examples

api.document(request)

From restfulapi.net: A document resource is a singular concept that is akin to an object instance or database record. In REST, you can view it as a single resource inside resource collection. A document’s state representation typically includes both fields with values and links to other related resources.

const api = require('@cloudifyjs/restful').api

// GET /cars/{id}
module.exports.get = api.document({
  target: async (request) => ({
    id: 1,
    name: 'Model S',
    vendor: 'Tesla'
  })
})

Response:

HTTP 200
Content-Type: application/json

{
  "id": 1,
  "name": "Model S",
  "vendor": "Tesla"
}

Wow! The above example demostrates how to response a document by wrappping a business function that returns a simple JSON.

api.collection(request)

From restfulapi.net: A collection resource is a server-managed directory of resources. Clients may propose new resources to be added to a collection. However, it is up to the collection to choose to create a new resource or not. A collection resource chooses what it wants to contain and also decides the URIs of each contained resource.

const api = require('@cloudifyjs/restful').api

// GET /cars
module.exports.list = api.collection({
  target: async (request) => ([
    {
      id: 1,
      name: 'Model S',
      vendor: 'Tesla'
    },
    {
      id: 2,
      name: 'Model 3',
      vendor: 'Tesla'
    }
  ])
})

Response:

HTTP 200
Content-Type: application/json

[
  {
    "id": 1,
    "name": "Model S",
    "vendor": "Tesla"
  },
  {
    "id": 2,
    "name": "Model 3",
    "vendor": "Tesla"
  }
]

The @cloudifyjs/restful provides the methods api.document and api.collection to exposes your RESTful endpoints. These methods handle requests received from the cloud provider (like aws, google, etc.) and deliver to the target function a normalized request object.

Using Joi validation

const Joi = require('@hapi/joi')
const api = require('@cloudifyjs/restful').api

module.exports.get = api.document({
  validators: {
    pathParameters: Joi.object({
      id: Joi.string().required()
    })
  },
  target: async (request) => {
    return {
      text: 'My task',
      checked: true
    }
  }
})

Options

  • consumes <String[]> (Optional): list of allowed values in Content-Type header, current only supports JSON formats (e.g. application/x-javascript, text/x-json). Default: application/json
  • vendor <String> (Optional): When specified, will not try automatically detect the cloud environment, currently the build-in vendors are aws and google.
  • decorator <Function> (Optional): used to provide custom response modification before serialize the target function response.
  • links <Object> (Optional): When provided will add links (HATEOAS) for each document returned.
  • target <Function> (Required): Indicates the function that will handle the incoming normalized requests.
  • validators <Joi.ObjectSchema> (Optional): Optional validation to be applied before the incoming request reach the target function, when invalid a HTTP 400 is returned.
    • body <Joi.ObjectSchema> (Optional); Joi Schema to validate the request body.
    • headers <Joi.ObjectSchema> (Optional): Joi Schema to validate the request headers.
    • pathParameters <Joi.ObjectSchema> (Optional): Joi Schema to validate the request pathParameters.
    • queryParameters <Joi.ObjectSchema> (Optional): Joi Schema to validate the request queryParameters.

Logging

By default, all logging messages are surpressed. You can optionally activate them as follows:

const { api, logger } = require('@cloudifyjs/restful')

logger.debug = console.debug
logger.error = console.error
logger.info = console.info
logger.log = console.log
logger.warn = console.warn

Custom cloud provider implementation

Example

'use strict';

const { api, vendors, logger } = require('@cloudifyjs/restful')

// declare a new supported vendor 'azure'
vendors.azure = (...args) => {
  const context = args[0];
  const req = args[1];

  return {
    request: {
      body: req.rawBody,
      headers: req.headers,
      httpMethod: req.method,
      path: req.originalUrl,
      pathParameters: req.params,
      queryParameters: req.query
    },
    resolve: result => {
      context.res = {
        body: result.body,
        headers: result.headers,
        status: result.statusCode
      };
      context.done();
    },
    reject: error => {
      logger.error(error);
      context.done(error);
    }
  };
}

module.exports.hello = api.document({
  vendor: 'azure', // inform to API that HTTP request will be normilized by 'azure' function
  target: async () => {
    return { message: `Hello World!` }
  }
})

If you are implementing any vendor not supported yet by @cloudifyjs/restful, feel free to create a pull request and suggest it built-in vendors.

Supported Node Versions

@cloudifyjs/restful aims to support the Node.js LTS.

| Node Release | Supported | | :--: | :---: | | 13.x | Yes | | 12.x | Yes | | 11.x | Yes | | 10.x | Yes | | 8.x | Yes |

Documentation

Please see the files in the docs directory:

License

This source code is licensed under the MIT license found in the LICENSE.txt file.