keystone-rest-api

0.9.8 • Public • Published

Keystone Rest API

This extension for Keystone is intended to create a REST API very easy. Also is prepared to output the Documentation for the created API. The Documentation is based on API Blueprint ( Format 1A8 ).

Features

  • Automatic REST API
  • API Documentataion

Documentation

http://sarriaroman.github.io/Keystone-Rest-API

Options

  • Model

    • rest {Boolean}

    • restOptions {String} 'list show create update delete'

    • restDescription {String}

  • List Object

    • restHooks {Object}
{
    list: [listMiddleware],
    show: [showMiddleware],
    create: [createMiddleware],
    update: [updateMiddleware],
    delete: [deleteMiddleware]
}
  • Fields
    • restSelected {Boolean}

    • restEditable {Boolean}

Usage

    var keystone = require('keystone'),
        fs = require('fs'),
      	Types = keystone.Field.Types,
      	keystoneRestApi = require('keystone-rest-api');

    var User = new keystone.List('User', {
        rest: true,
        restOptions: 'list show create update delete'
    });

    User.add({
      	name: { type: Types.Name, required: true, index: true },
      	password: { type: Types.Password, initial: true, required: false, restSelected: false },
      	token: { type: String, restEditable: false }
    });
    
    User.restHooks = {
      	list: [listMiddleware],
      	show: [showMiddleware],
        create: [createMiddleware],
      	update: [updateMiddleware],
      	delete: [deleteMiddleware]
    };

    User.register();

    // Make sure keystone is initialized and started before
    // calling createRest
    keystone.init(config);
    keystone.start();

    // Add routes with Keystone
    keystoneRestApi.createRest(keystone, {
        apiRoot: '/api/v1/'
    });
    
    // Create Documentation and write it to a file
    fs.writeFileSync('api.md', keystoneRestApi.apiDocs(), 'UTF-8');

Changelog

0.9.7.1

  • Added ignoreNoEdit to Create to avoid awful errors for now

0.9.7

  • restDescription field to specify the Description of the REST Endpoint
  • Use of keystone Name to create the Header of the Blueprint API Document

0.9.6

  • Added attributes to Model Definition in the Documentation
  • Added Support for Select Field on API Generation
  • Added support for Required in Documentation

0.9.5

  • Added support for UpdateHandler

TODO

  • The "update" and "create" method must use the Keystone UpdateHandler (Done)
  • Implement a way to set Options for UpdateHandler
restOptions: {
    ignoreNoedit: true
}
  • New Tests based on the changes.

Authors

Package Sidebar

Install

npm i keystone-rest-api

Weekly Downloads

3

Version

0.9.8

License

ISC

Last publish

Collaborators

  • sarriaroman