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

uberman

v0.1.0

Published

framework for quickly developing pragmatic REST APIs

Downloads

2

Readme

Uberman

A better way to REST

by Elvin Yung

Develop and deploy REST APIs quickly with less boilerplate code.

Introduction

Uberman is an opinionated Node.js HTTPS JSON REST API framework, powered by Express.js and MongoDB.

Quickstart

Install from NPM.

Suppose we want to create a REST API for a blog, which exposes a single endpoint for blog posts. The code to do that is as follows:

var uberman = require('uberman');
var blogAPI = uberman({
    certPath: // PATH TO SSL CERT
    keyPath: // PATH TO SSL KEY
});

blogAPI.addEndpoint('blogPosts', {
    title: String,
    body: String,
    created: {
        type: Date,
        default: Date.now
    },
    upvotes: Number
});

blogAPI.listen();

uberman(config) creates an API and applies the given config. keyCert and keyPath are required fields in the config and must respectively point to an TLS/SSL certificate file and its corresponding private key. Other fields in the config will be discussed later in this readme.

addEndpoint(name, schema[, options]) adds an endpoint in the API with the given schema, and the supplied options. The name is camelized to create the MongoDB collection, and dasherized to create the route. (For example, an endpoint named xTreMeKoolEndPoint would be routed to x-tre-me-kool-end-point, and have a Mongoose model named xTreMeKoolEndPoint.)

In the context of the quickstart example, the route blogPosts was created in the blogAPI, routed to /blog-posts, and backed by a Mongoose model named blogPosts. The following default operations on the endpoint, are also generated:

  • a query operation on GET /blog-posts. This is queriable through parameters in the query string.
  • a create operation on POST /blog-posts. This accepts only valid JSON with the Content-Type header as application/json.
  • a retrieve operation on GET /blog-posts/:id.
  • a replace operation on PUT /blog-posts/:id. This accepts only valid JSON with the Content-Type header as application/json.
  • an upsert operation on PATCH /blog-posts/:id. This accepts only valid JSON with the Content-Type header as application/json.
  • a destroy operation on DELETE /blog-posts/:id

These operations are compliant with RFC 2616 and RFC 5789.

listen([port], [host]) binds connections in the given host and port to the API. By default, Uberman APIs listen on localhost port 443, and accepts only HTTPS connections.

Resources

When you build an endpoint using addEndpoint(name, schema[, options]), you provide a schema, which is the structure of the endpoint's resource, outlined in terms of the fields that the resource contains. Uberman exposes field types through the uberman.Types object, which is essentially a layer on top of the Mongoose Schema.Types. The following types are supported:

String

Number

Date

Buffer

Boolean

Mixed

foreignKey

arrays

nested data

Below is an example schema.

{
    name: String,
    score: Number,
    birthday: Date,

}

Routing

Uberman dasherizes all endpoint routes, and places them under the API root.

The API root is by default set to /api/v{version}, where {version} is the API version set in the config, which is 0 by default. You can change it using the root config field, or the version field if you just want to change the version.

Requests and Responses

By default, Uberman accepts only JSON request bodies (with the Content-Type header as application/json), and returns JSON response bodies. In all cases, the body of the response is unenveloped, and the resource or collection serialized is the entire response body. Any metadata is put in headers.

Uberman uses HATEOAS in its responses. For Uberman, this means that in response bodies, all foreign keys are represented as hyperlinks to the resource referred to.