Skip to content

Latest commit

 

History

History
151 lines (99 loc) · 3.82 KB

README.md

File metadata and controls

151 lines (99 loc) · 3.82 KB

loopback-nodejs-client

NPM Version Coverage Status Build Status Downloads Dependency Status License

NodeJS client library with loopback SDK syntax

Install

$ npm install --save loopback-nodejs-client

Usage

Without authentification

var LoopbackClient = require('loopback-nodejs-client')

var loopbackClient = new LoopbackClient('http://localhost:3000/api');

var Customers = loopbackClient.getModel('customers')

Customers.create({name: 'ido4pro', city: 'plougonvelin'})
  .then(function (customer) {
    console.log(customer)

    Customers.find({filter: {where: {name: 'ido4pro'}}})
      .then(function (customers) {
        console.log(customers)

      })
      .catch(function (err) {
        console.log(err)
      })

    Customers.count({where: {name: 'ido4pro'}})
      .then(function (customers) {
        console.log(customers)

      })
      .catch(function (err) {
        console.log(err)
      })

  })
  .catch(function (err) {
    console.log(err)
  })

With authentification

var loopbackClientWithAuth = new LoopbackClient('http://localhost:3000/api','xxx EMAIL USER xxx', 'xxx PASSWORD xxx')

var Customers = loopbackClient.getModel('customers')

loopbackClient.createToken()
  .then(function()
  {
      
       Customers.count({where: {name: 'ido4pro'}})
            .then(function (customers) {
              console.log(customers)
      
            })
            .catch(function (err) {
              console.log(err)
            })
      
  })

Methods

create(data) --> data = { id: 'xxx', filter: {...} } (filter is optional)

count(where) --> where = { where : {name: 'xxx'} }, where = { where: {and: [{name: 'xxx'},{city: 'xxx'}]

updateAll(where,data)

updateById(id,where)

find(filter)

findById(data)

findOne(query)

deleteById(id)

Check the test/index.js for more usage

License

MIT © Stéphane GUILLY