Skip to content

limoli/express-api-descriptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple, fast and customizable

In descriptor you can add the object representing the parameters that you need.

app.get('/books', function (req, res) {
    res.send("My fantastic book");
}).descriptor({
    name : 'Retrieve a fantastic book',
    errors : []
});

Retrieve API list

api.list() : retrieve all the mapped Express APIs.

app.get('/apis', function (req, res) {
    res.send(api.list());
}).descriptor({
    name : 'Retrieve APIs documentation'
});

Retrieve API list grouped by entities

api.listByEntity() : retrieve all the mapped Express APIs grouping by entity. There are 2 modes:

  • automatic : entities are detected automatically according to restful api concepts
app.get('/api/gardens', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'Welcome in my garden!',
    errors : []
});

app.post('/api/gardens', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'I need a new garden',
    errors : []
});

app.get('/api/gardens/flowers', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'Look my tulips!',
    errors : []
});
  • manual : just add the parameter entity in your api
app.get('/api/gardens', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'Welcome in my garden!',
    errors : [],
    entity : 'My Garden'
});

app.post('/api/gardens', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'I need a new garden',
    errors : [],
    entity : 'My Garden'
});

app.get('/api/gardens/flowers', function (req, res) {
    res.send(api.listByEntity());
}).descriptor({
    name : 'Look my tulips!',
    errors : [],
    entity : 'My flowers'
});

Usage

The express-api-descriptor module allows to create documentation for Express APIs.

var express = require('express');
var api = require('express-api-descriptor')(express);
var app = express();

app.get('/api', function (req, res) {
    res.send(api.list());
}).descriptor({
    name : 'My first API documentation'
});

app.listen(8080, function () {
    console.log('Example app listening on port 8080!');
});

Installation

npm i express-api-descriptor

Last updates

From Version 1.0.3

  • Possibility to group API by entity automatically

License

ISC

About

Provide a simple, fast and customizable system to manage API documentation using Express framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published