https://github.com/andywer/koa-router-index
Koa v2 middleware to create an index page for API servers.
https://github.com/andywer/koa-router-index
Last synced: 11 months ago
JSON representation
Koa v2 middleware to create an index page for API servers.
- Host: GitHub
- URL: https://github.com/andywer/koa-router-index
- Owner: andywer
- License: mit
- Created: 2017-09-13T21:26:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T19:42:40.000Z (over 7 years ago)
- Last Synced: 2025-06-01T12:53:24.523Z (about 1 year ago)
- Language: JavaScript
- Size: 236 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-router-index
[](https://travis-ci.org/andywer/koa-router-index) [](https://www.npmjs.com/package/koa-router-index) [](http://standardjs.com/)
Middleware to generate an index page for REST API services. For usage with [koa](https://github.com/koajs/koa) v2 and [koa-router](https://github.com/alexmingoia/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.
## Installation
```sh
npm install --save koa-router-index
```
## Usage
```js
const IndexPage = require('koa-router-index')
app.use(
IndexPage(koaRouter, options /* (optional) */)
)
```
A more comprehensive example:
```js
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