README
Loopback API for Node.js
Installation
Loopback requires Node.js v4+ to run. If you want install Loopback local to your project use
$ npm install --save loopback-api
Or for global install use
$ npm install -g loopback-api
Usage
const LoopbackAPI = require('loopback-api').LoopbackAPI;
var loopbackAPI = new LoopbackAPI('http://localhost:3100/api');
var Users = loopbackAPI.getModel('Users');
// WITH PROMISE
Users.find({
where: {
name: 'Jon'
}
}).then(users => {
console.log('users: ', users);
});
// WITH ASYNC/AWAIT
async () => {
var user = await Users.findById(1);
console.log('user: ', user);
}();
Base methods
Each model has the following methods:
- findById(id)
- create(data)
- count(where)
- updateById(id, data)
- find(filter)
- findOne(filter)
- update(where, data)
- deleteById(id)
- delete(where): deleteAll must be active on your server Loopback to use this method.
Where inputs are:
- filter: is a JSON object containing the query filters. See filter Loopback.
- where: is a JSON object containing specifies a set of logical conditions to match, similar to a WHERE clause in a SQL query. See where Loopback
- data: is a JSON object containing the single model instance or an array instances.
Debug
When you start your application set DEBUG environment variable so you can see all debug messages of Loopback API package.
DEBUG=LP* node your_app.js
Contributors
License
MIT