GithubHelp home page GithubHelp logo

petitchevalroux / loopback-nodejs-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from s3pweb/loopback-nodejs-client

0.0 1.0 0.0 17 KB

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

License: Other

JavaScript 100.00%

loopback-nodejs-client's Introduction

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

loopback-nodejs-client's People

Contributors

ido4pro avatar petitchevalroux avatar sguilly avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.