npm.io
1.13.0 • Published 6 years ago

loopback-advancedmodel

Licence
MIT
Version
1.13.0
Deps
1
Size
29 kB
Vulns
0
Weekly
0
Stars
3
DeprecatedThis package is deprecated

Loopback-advancedmodel

version Maintenance MIT dep size Known Vulnerabilities

Improved model component for Loopback version 3.x

Features

  • Async & Await support
  • Register multiple validators on one property at once.
  • Better generic errors handler.
  • Object-oriented descriptor for OpenAPI (Swagger 2.0).
  • Basic ACLs management support

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i loopback-advancedmodel
# or
$ yarn add loopback-advancedmodel

Usage example

Setup your loopback project as usual and then start writing a new model (for example User).

Require the advancedmodel class from the package and use it as follow :

const advancedmodel = require('loopback-advancedmodel');

// Create your User Model
const User = new advancedmodel().disableAllMethods();

async function sayHello() {
    return "hello world!";
}
// Register the Asynchronous method sayHello on User model and Get the OpenAPI Descriptor Object.
const OpenAPIDescriptor = User.registerRemoteMethod(sayHello);

// Setup classical OpenAPI informations about our REST Endpoint.
OpenAPIDescriptor.get('/sayHello').returns({ type: 'string' });

// Export the User model
module.exports = User.export();

API

Find all documentation on the wiki section right here

License

MIT