How to use the loopback.rest function in loopback

To help you get started, we’ve selected a few loopback examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mschmulen / tracking-bluetooth-ibeacons-with-node / ibeacon-node-collector / app.js View on Github external
app.use(loopback.bodyParser());
app.use(loopback.methodOverride());

/*
 * EXTENSION POINT
 * Add your custom request-preprocessing middleware here.
 * Example:
 *   app.use(loopback.limit('5.5mb'))
 */

/*
 * 3. Setup request handlers.
 */

// LoopBack REST interface
app.use(app.get('restApiRoot'), loopback.rest());

// API explorer (if present)
try {
  var explorer = require('loopback-explorer')(app);
  app.use('/explorer', explorer);
  app.once('started', function(baseUrl) {
    console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
  });
} catch(e){
  console.log(
    'Run `npm install loopback-explorer` to enable the LoopBack explorer'
  );
}

/*
 * EXTENSION POINT
github beeman / angular-restangular-crud / api / app.js View on Github external
app.use(loopback.bodyParser());
app.use(loopback.methodOverride());

/*
 * EXTENSION POINT
 * Add your custom request-preprocessing middleware here.
 * Example:
 *   app.use(loopback.limit('5.5mb'))
 */

/*
 * 3. Setup request handlers.
 */

// LoopBack REST interface
app.use(app.get('restApiRoot'), loopback.rest());

// API explorer (if present)
try {
  var explorer = require('loopback-explorer')(app);
  app.use('/explorer', explorer);
  app.once('started', function(baseUrl) {
    console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
  });
} catch(e){
  console.log(
    'Run `npm install loopback-explorer` to enable the LoopBack explorer'
  );
}

/*
 * EXTENSION POINT
github strongloop / loopback-connector-soap / example / weather-rest.js View on Github external
loopback.remoteMethod(
    WeatherService.weather, {
      accepts: [
        {arg: 'zip', type: 'string', required: true,
          http: {source: 'query'}}
      ],
      returns: {arg: 'result', type: 'object', root: true},
      http: {verb: 'get', path: '/weather'}
    }
  );

  // Expose to REST
  app.model(WeatherService);

  // LoopBack REST interface
  app.use(app.get('restApiRoot'), loopback.rest());
// API explorer (if present)
  try {
    var explorer = require('loopback-explorer')(app);
    app.use('/explorer', explorer);
    app.once('started', function (baseUrl) {
      console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
    });
  } catch (e) {
    console.log(
      'Run `npm install loopback-explorer` to enable the LoopBack explorer'
    );
  }

  app.use(loopback.urlNotFound());
  app.use(loopback.errorHandler());
github strongloop / loopback-example-offline-sync / rest / rest.js View on Github external
// dependencies
var loopback = require('loopback');
var boot = require('loopback-boot');

// server
var server = module.exports = loopback();

boot(server, __dirname);

// middleware
server.use(loopback.rest());
github strongloop / loopback-example-offline-sync / app.server.js View on Github external
// setup the model data sources
User.attachTo(memory);
Todo.attachTo(memory);

// root api path
var apiPath = '/api';

// enable authentication
server.enableAuth();

// middleware
server.use(loopback.static(path.join(__dirname, 'public')));
server.use(loopback.static(path.join(__dirname, 'bower_components', 'angular-route')));
server.use(loopback.token());
server.use(apiPath, loopback.rest());
server.use('/explorer', explorer(server, {basePath: apiPath}));

// locals
server.locals({
  title: 'Todo Example'
});

// view engine
server.engine('html', require('ejs').renderFile);

// home route
server.get('/', function(req, res) {
  var token = req.accessToken;
  var data = {me: undefined};

  if(token) {
github backstage / loopback-jsonschema / test / support.js View on Github external
newLoopbackJsonSchemaApp: function(config) {
        var app = loopback();
        app.set('restApiRoot', '/api');
        loopbackJsonSchema.init(app, config || {});
        loopbackJsonSchema.enableJsonSchemaMiddleware(app);
        app.use(app.get('restApiRoot'), loopback.rest());
        app.use(loopback.errorHandler());
        return app;
    }
};
github strongloop / loopback-multitenancy / test / integration / model-resolver.js View on Github external
it('maps the URL to a namespaced URL', function(done) {
    var observedUrl;
    app.use(function(req, res, next) {
      observedUrl = req.url;
      next();
    });
    app.use(app.get('restApiRoot'), loopback.rest());
    request(app).get('/api/1/Joe/Todos').end(function(err, res) {
      if (err) return done(err);
      expect(observedUrl).to.equal('/api/1_Joe_Todos');
      done();
    });
  });
github digitalsadhu / loopback-jsonapi-model-serializer / test / serializer.spec.js View on Github external
app.model(Post)
  app.model(Author)
  app.model(Comment)
  app.model(Parent)
  app.model(Critic)
  app.model(Empty)

  Comment.belongsTo(Post)
  Post.hasMany(Comment)
  Post.belongsTo(Author)
  Post.belongsTo('parent', {polymorphic: true})
  Post.hasAndBelongsToMany(Critic)
  Author.hasMany(Post)
  Author.hasMany(Comment, {through: Post})

  app.use(loopback.rest())
})
github digitalsadhu / loopback-jsonapi-model-serializer / test / performance.spec.js View on Github external
const ds = loopback.createDataSource('memory')

  const Post = ds.createModel('post', {title: String})
  const Comment = ds.createModel('comment', {title: String})
  const Author = ds.createModel('author', {name: String})

  app.model(Post)
  app.model(Author)
  app.model(Comment)

  Post.hasMany(Comment)
  Post.belongsTo(Author)
  Comment.belongsTo(Author)

  app.use(loopback.rest())
})
github strongloop / loopback-connector-remote / test / helper.js View on Github external
function createRestAppAndListen() {
  const app = loopback({localRegistry: true});

  app.set('host', '127.0.0.1');
  app.set('port', 0);

  app.set('legacyExplorer', false);
  app.set('remoting', {
    errorHandler: {debug: true, log: false},
    context: false,
  });

  app.use(loopback.rest());
  app.locals.handler = app.listen();

  return app;
}