Skip to content

An endpoint documentation plugin for HapiJS

Notifications You must be signed in to change notification settings

Alainmma/hapi-ending

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hapi Ending

Lists routes, parameters, and validation constraints for HAPI version 17.x.

CircleCI JavaScript Style Guide

Thanks

Original plugin by Antony Jones, updated for Hapi v17+ by Yulia Tenincheva

  • For HapiJS < v17, use branch hapi-pre-v17 or npm tag 0.9.2
  • For HapiJS > v17, use master, or npm tag > ^1.0.0

What it looks like

Hapi Ending

Configuration

Currently you can configure the baseUrl which is useful if you want to copy and paste urls, and whether the plugin is enabled or not. Disabling the plugin is highly advised for production environments.

var options = {
    baseUrl: 'http://your.domain:1234' // defaults to protocol-less server host+port,
    enabled: true // defaults to false,
    assetsPath: '/mount-point-for-plugin-assets' // defaults to 'assets' - change if this conflicts with your own routes,
    logoUrl: 'http://example.net/logo.webp'
}

Live Demo

To run a quick local demo, use the npm target 'demo':

npm run demo

Usage

Install the plugin in the standard way:

server.register([
    {
        plugin: require('hapi-ending'),
        options: options
    }
], (err) => {
    ...
}

Describing endpoints

You can add a description to routes using the parameters 'description', 'tags', and 'notes' as follows:

    {
        method: 'GET',
        path: '/you/{foo}/name/{baz}',
        options: {
            description: "Describe your endpoint here",
            tags: ['foo', 'authenticated', 'any tag']
            validate: {
                query: {
                    a: Joi.number().description('This is where you put the number of As'),
                    now: Joi.boolean().description('Whether I should do it now or later')
                },
                params: {
                    foo: Joi.number().description('It should more than likely be a number'),
                    baz: Joi.string().description('Some string thing goes here')
                }
            },
            notes: [
                'This is just a note'
            ]
        },
        handler: function(request, h) {
            ...
        }
    }

Private endpoints

Adding 'private' to any endpoint's tags will make the endpoint private (i.e. unlisted by the plugin)

About

An endpoint documentation plugin for HapiJS

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 83.4%
  • HTML 15.5%
  • CSS 1.1%