Git Product home page Git Product logo

koa-router-index's Introduction

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

koa-router-index's People

Contributors

andywer avatar lukeapage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lukeapage

koa-router-index's Issues

Add JSON output mode

  • Should have a HATEOAS-ish data model
  • Should be used when request Accept headers does not contain text/html
  • Should be used when a special query parameter is used (?format=json ?)
  • HTML page should contain a link to the JSON index page

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.