koa-router-index

0.2.0 • Public • Published

koa-router-index

Build Status NPM Version JavaScript Style Guide

Middleware to generate an index page for REST API services. For usage with koa v2 and koa-router.

Why? Because an API service should tell you which endpoints it provides. You should not have to google the service's documentation to be able to use it.

Screenshot

Installation

npm install --save koa-router-index

Usage

const IndexPage = require('koa-router-index')
 
app.use(
  IndexPage(koaRouter, options /* (optional) */)
)

A more comprehensive example:

const Koa = require('koa')
const Router = require('koa-router')
const IndexPage = require('koa-router-index')
 
const router = new Router()
  .get('/user/:id', userHandler)
  .get('/status', statusHandler)
 
const app = new Koa()
  .use(router.routes())
  .use(IndexPage(router, { meta: { name: 'My fancy API server' } }))
  // or
  .use(IndexPage(router, { meta: require('./package.json') }))

Options

meta: Object

Properties (all optional):

  • name - The name of the service.
  • description - A short description of the service.

The property names match the ones in package.json, so you can just pass your parsed package.json here.

excludeMethods: String[]

Array of HTTP methods to ignore when creating the index page. Defaults to [ 'HEAD' ].

prefix: String

The prefix to add the index under.

License

MIT

Package Sidebar

Install

npm i koa-router-index

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

92.7 kB

Total Files

10

Last publish

Collaborators

  • andywer