How to use the loopback.createDataSource 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 strongloop / loopback-connector-jsonrpc / example / app.js View on Github external
const jayson = require('jayson');

// create a server
const server = jayson.server({
  add: function(args, callback) {
    callback(null, args[0] + args[1]);
  },
  subtract: function(args, callback) {
    callback(null, args[0] - args[1]);
  },
});

const loopback = require('loopback');

const ds = loopback.createDataSource({
  connector: require('../index'),
  debug: false,
  url: 'http://localhost:3000',
  operations: ['add', 'subtract']});

const model = ds.createModel('dummy');

const app = loopback();

app.use(loopback.rest());
app.use(server.middleware(server));

// Bind a http interface to the server and let it listen to localhost:3000
const s = app.listen(3000, function() {
  model.add(1, 2, function(err, data) {
    console.log(err, data);
github strongloop / loopback-connector-soap / example / weather-rest.js View on Github external
var loopback = require('loopback');
var path = require('path');

var app = module.exports = loopback();

app.set('restApiRoot', '/api');

var ds = loopback.createDataSource('soap',
  {
    connector: require('../index'),
    remotingEnabled: true,
    // wsdl: 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL' // The url to WSDL
    wsdl: path.join(__dirname, './weather.wsdl')
  });

// Unfortunately, the methods from the connector are mixed in asynchronously
// This is a hack to wait for the methods to be injected
ds.once('connected', function () {

  // Create the model
  var WeatherService = ds.createModel('WeatherService', {});

  // Refine the methods
  WeatherService.forecast = function (zip, cb) {
github strongloop / loopback-example-push / loopback / app.js View on Github external
// Copyright IBM Corp. 2015. All Rights Reserved.
// Node module: loopback-example-push

var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();

// Load up the push data source as the example cannot declaratively define
// the push data source in datasources.json as it cannot resolve the connector
// module by name
var connector = require('loopback-component-push');
app.dataSources.push = loopback.createDataSource("push", {
  "defaultForType": "push",
  "connector": connector
});

/*
 * 1. Configure LoopBack models and datasources
 *
 * Read more at http://apidocs.strongloop.com/loopback#appbootoptions
 */
app.boot(__dirname);


/*
 * 2. Configure request preprocessing
 *
 *  LoopBack support all express-compatible middleware.
github strongloop / loopback-connector-soap / example / stock-ws.js View on Github external
var loopback = require('loopback');

var ds = loopback.createDataSource('soap',
  {
    connector: require('../index'),
    wsdl: 'http://www.webservicex.net/stockquote.asmx?WSDL', // The url to WSDL
    url: 'http://www.webservicex.net/stockquote.asmx', // The service endpoint

    // Map SOAP service/port/operation to Node.js methods
    operations: {
      // The key is the method name
      stockQuote: {
        service: 'StockQuote', // The WSDL service name
        port: 'StockQuoteSoap', // The WSDL port name
        operation: 'GetQuote' // The WSDL operation name
      },
      // The key is the method name
      stockQuote12: {
        service: 'StockQuote', // The WSDL service name
github strongloop / loopback-connector-swagger / test / test-connector-auth.js View on Github external
function createDataSource(spec, authz) {
  return loopback.createDataSource('swagger', {
    connector: require('../index'),
    spec: spec,
    security: authz,
  });
}
github strongloop / loopback-connector-swagger / test / test-connector.js View on Github external
function createDataSource(spec, options) {
  const config = Object.assign({
    connector: require('../index'),
    spec: spec,
  }, options);
  return loopback.createDataSource('swagger', config);
}
github digitalsadhu / loopback-jsonapi-model-serializer / test / performance.spec.js View on Github external
test.beforeEach(t => {
  const app = t.context.app = loopback()
  app.set('legacyExplorer', false)

  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 dashby3000 / loopback-connector-twilio / example / example.js View on Github external
type: 'call',
    to: TO,
    from: FROM,
    url: 'https://raw.githubusercontent.com/dashby3000/loopback-connector-twilio/master/example/call.xml'
};

const emailData = {
    type: 'email',
    to: TO,
    from: FROM,
    subject: 'Sending with SendGrid & LoopBack is Fun',
    text: 'and easy to do anywhere, even with LoopBack/Node.js',
    html: '<strong>and easy to do anywhere, even with LoopBack/Node.js</strong>',
};

var ds = require('loopback').createDataSource({connector: require('../'), accountSid: SID, authToken: TOKEN, sgAPIKey: SGAPIKEY});

var Twilio = ds.createModel('twilio', {
    type: {type: String, id: true, required: true},
    to: {type: String, required: true},
    from: {type: String, required: true},
    body: {type: String, required: true},
    url: {type: String, required: true}
});

Twilio.send(smsData, function (err, data) {
    if (err) {
        console.log(err);
    } else {
        console.log(data);
    }
});
github strongloop / loopback-workspace / common / models / data-source-definition.js View on Github external
DataSourceDefinition.prototype.toDataSource = function() {
    return loopback.createDataSource(this.name, this);
  };
github strongloop / loopback-connector-rest / example / rest-loopback-geocode.js View on Github external
var loopback = require("loopback");

var ds = loopback.createDataSource({
  connector: require("../index"),
  strictSSL: false,
  debug: false,
  defaults: {
    "headers": {
      "accept": "application/json",
      "content-type": "application/json"
    }
  },
  operations: [
    {
      template: {
        "method": "GET",
        "url": "http://maps.googleapis.com/maps/api/geocode/{format=json}",
        "query": {
          "address": "{street},{city},{zipcode}",