coder6421 / loopback-nodejs-client

A nodejs client to call loopback api server with official sdk methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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')

loopbackClientWithAuth.createToken()
  .then(function()
  {
      
       var Customers = loopbackClientWithAuth.getModel('customers')
       
       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

About

A nodejs client to call loopback api server with official sdk methods

License:Other


Languages

Language:JavaScript 100.0%