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

hypermediadoc

v1.0.10

Published

Node.js module to generate markdown documentation for Hypermedia APIs.

Downloads

6

Readme

NPM version Dependency Status

Node.js module to generate markdown or HTML documentation for Hypermedia APIs.

Features

Generates documentation in markdown or HTML for Hypermedia REST APIs that are described in JSON.

Install

$ npm install hypermediadoc --save

Usage

Describe your API, Relations and Resources as JSON according to the JSON Schema located at ./schema/hypermediadoc.json The module will then generate markdown documentation and optionally also HTML.

var hypermediadoc = require('hypermediadoc');

var apiDefinition = {
  "title": "MyTest REST API",
  "description": "Documentation for the fabulous Example API",
  "entryPoint": "http://example.com/api",
  "mediaType": {
    "identifier": "application/hal+json",
    "name": "HAL",
    "link": "https://tools.ietf.org/html/draft-kelly-json-hal-06"
  },
  "richardsonMaturityLevel": 3,
  "restExplanation": "The MyTest API is a *REST API,* or rather *Hypermedia API.* This means that the term *REST* is actually understood as [intended by Roy T. Fielding](http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm) – including the *Hypermedia Constraint.* See [this blog post](http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven) for a more in-depth description of REST and the difference to a simple HTTP-based API which is often mistakenly called *REST API.*\n\nIn short, data is partitioned in *resources* which manifest in *representations.* Those are transferred using a *standardized format* ([JSON HAL](https://tools.ietf.org/html/draft-kelly-json-hal-06)) with *standardized methods* (HTTP/1.1, [RFC 7230](http://tools.ietf.org/html/rfc7230)). Application flow between resources is defined by link relations. URLs are subject to change and must not be hard coded. Instead, link relations can be used to explore and use the APIs.",
  "moreDocContent": "",
  "relations": [
    {
      "title": "myapi:account",
      "description": "Display a user account",
      "resource": {
        "name": "example:account",
        "href": "../account"
      },
      "method": "get",
      "templated": [
        {
          "key": "id",
          "description": "ID of an account"
        }
      ]
    }
  ],
  "commonRelations": [
    "collection",
    "curies",
    "first",
    "item",
    "next",
    "prev",
    "self"
  ],
  "resources": [
    {
      "title": "account",
      "description": "A single account.",
      "embeddedResourceInListResource": {
        "description": "This resource is always output as a list with embedded single resources.\nThe structure of an embedded resource is as follows:",
        "schema": "http://example.com/account",
        "links": [
          {
            "relation": "self",
            "description": "A single account",
            "methods": [
              "get",
              "put"
            ],
            "templated": false
          }
        ],
        "properties": [
          {
            "name": "accountID",
            "description": "The unique identifier for an account.",
            "optional": false
          }
        ]
      },
      "methods": [
        {
          "name": "get",
          "description": "Show account list.",
          "request": {
            "schema": "",
            "headers": [{
              "header": "Authorization",
              "value": "Basic",
              "description": "",
              "optional": false
            }],
            "query": [
              {
                "name": "id",
                "description": "filter by id, exact-match",
                "optional": true,
                "group": "Filters"
              },
              {
                "name": "page",
                "description": "pagination page value",
                "optional": true,
                "group": "Pagination"
              }
            ],
            "properties": [
              {
                "name": "id",
                "description": "filter by id, exact-match",
                "optional": true
              },
              {
                "name": "page",
                "description": "pagination page value",
                "optional": true
              }
            ],
            "description": "Some additional text to explain the request."
          },
          "responses": [
            {
              "code": 200,
              "schema": "",
              "description": "",
              "headers": {
                "www-authenticate": "basic"
              },
              "links": [
                {
                  "relation": "self",
                  "description": "A single account",
                  "methods": [
                    "get",
                    "put"
                  ],
                  "templated": false
                }
              ],
              "properties": [
                {
                  "name": "accountID",
                  "description": "The unique identifier for an account.",
                  "optional": false
                }
              ],
              "embedded": [
                {
                  "name": "account",
                  "href": "#embeddedResource"
                }
              ],
              "example": {
                "accountID": "y2o38h"
              }
            }
          ]
        }
      ]
    }
  ]
};

var markdown = hypermediadoc.getDoc('root', apiDefinition, 'markdown');
var html = hypermediadoc.getDoc('root', apiDefinition, 'html');


// single resource:
markdown = hypermediadoc.getDoc('resource', apiDefinition.resources[0], 'markdown');
html = hypermediadoc.getDoc('resource', apiDefinition.resources[0], 'html');

API

hypermediadoc.getDoc(type, source, format)

Synchronous function. Returns a markdown or html string.

type can be one of:

  • root – an overview page with general information
  • resource – a resource detail page
  • relation – a relation detail page
  • resourceList – a list of available resources
  • relationList – a list of available relations

source is the API definition as JSON or a specific resource or relation part of that when type is resource or relation.

format can be markdown or html. Note that no full HTML page is rendered, just the content part.

If illegal values are given or if source is not valid according to the JSON schema, errors are thrown. So you should wrap the function call in a try...catch construct.

Customization

Templates

The module uses Handlebars as template engine for the markdown files. They are located in ./templates.

The following Handlebars helpers are available:

  • toUpperCase – UPPERCASES a string
  • toLowerCase – lowercases a string
  • boolToEnglish – translates true to 'Yes' and false to No.
  • httpExplain – returns the description for a HTTP status code (200: ok, 404: not found, …)
  • richardsonExplain – returns the description for a Richardson Maturity Level
  • stringify – JSON.stringify()
  • grouped-list – groups a collection by the value in group. The group name is available in @key, the sub-collection in this.

Tests

mocha

Changelog

1.0.10

  • updated dependencies

1.0.9

  • updated dependencies

1.0.8

  • updated dependencies

1.0.7

  • updated dependencies

1.0.6

  • updated dependencies

1.0.5

  • updated dependencies

1.0.4

  • updated dependencies

1.0.3

  • updated dependencies

1.0.2

  • updated dependencies

1.0.1

1.0.0

  • large overhaul (incompatible API changes…!)
  • new JSON Schema
  • only return the content part when HTML is requested, no full html page (no header, …)
  • added templates for root page, relation detail, and lists
  • improved API (only one method now). Old methods are deprecated but should still work.

0.0.3

  • added HTML parsing with marked

0.0.2

  • fix for usage as a node module
  • fixes for npm installation
  • improvements in schema and template

0.0.1

  • initial release

License

MIT © entrecode GmbH