Skip to main content

Posts

Showing posts from July, 2019

Custom application logic for Loopback models

This post is the continuation of the previous one .  What if you want to customize your REST API or add different methods for it? When building an application, you’ll generally need to implement custom logic to process data and perform other operations before responding to client requests. In Loopback there are 3 ways to do this: Adding logic to models Defining boot scripts Defining middleware For this post I'm explaining about the first one, Adding logic to models. There are 3 types to add custom application logic to model. Remote Method Remote Hook Operation Hook Remote Method : A remote-method is nothing but nodejs function mapped to REST endpoints. You can create remote-method by cli or typing by yourself ( click here to know how ).  In the previous post, I used memory db. For this one, I'm going to use MongoDB as datasource. You need to install loopback-connector-mongodb to connect to MongoDB. npm install loopback-connector-mongodb --save

Loopback by Strongloop : Getting started

Loopback is developed by Strongloop and maintained by IBM.  The LoopBack framework is a set of Node.js modules that you can use independently or together to quickly build REST APIs. Heart of Loopback is its models. The application interacts to data-source through models. The following diagram illustrates, How loopback works : Benefits of using Loopback over Express Loopback has a steep learning curve, on other side Express have a very little learning curve.  Loopback has built-in Database integration, whilst you need npm package in Express. Loopback has built-in models and authentication, API explorer, built-in ORM/ODM with the juggle and various driver and ACL. On the other side, Express needs separate npm package for all this. Node.Js is widely used for quickly wrapping up projects with REST APIs. You have to choose the framework that best suits you and the project. Installation : Prerequisite : Node.Js After making sure that you have Node.js installed