Loopback support for Node.js


Introduction

LoopBack is an award-winning, highly extensible, open-source Node.js based on Express. It enables you to quickly create APIs and microservices composed from backend systems such as databases and SOAP or REST services. For more information, see Loopbackexternal link framework.

Objects

This extension, when Loopback library is found in the source code, may create the following objects:

Icon Description
NodeJS Get Operation
NodeJS Post Operation
NodeJS Put Operation
NodeJS Delete Operation
NodeJS Patch Operation

Create webservice from Express API

The App extends and supports Express Middleware. Webservice can be supported as API Express framework:

var loopback = require('loopback');
var app = loopback();

// Create get method
app.get('/', function(req,res){
res.send('hello wor;ld')
});

app.listen(3000);

Create webservice from model

Model todo.js:

module.exports = function(Todo) {
  Todo.stats = function(filter, cb) {
  ...
  };
  ...
  Todo.remoteMethod('stats', {
    accepts: {arg: 'filter', type: 'object'},
    returns: {arg: 'stats', type: 'object'},
    http: { path: '/stats' }
  }, Todo.stats);
  ...
}

This will give the following result:

Exposing models over REST

Loopback models automatically have a standard set of HTTP endpoints that provide REST APIs. See https://loopback.io/doc/en/lb3/Exposing-models-over-REST.htmlexternal link for more information.

Example: todo.json:

{
  "name": "Todo",
  "base": "PersistedModel",
  "strict": "throw",
  "persisteUndefinedAsNull": true,
  "trackChanges": true,
  "properties": {
    "id": {
      "id": true,
      "type": "string",
      "defaultFn": "guid"
    },
    "title": "string",
    "completed": {
      "type": "boolean",
      "default": false
    },
    "created": {
      "type": "number"
    }
  }
}

This will give the following result: