Managing Loopback configuration files for multiple environments can be a hassle. In this blog we demonstrate how we do it using some well-known practices for scalable and maintainable codebases from the The Twelve-Factor App methodology. The key ideas are around storing configurations in environment variables rather than grouping configurations in a named group or polluting the codebase with configurations and constants.
When building models with LoopBack, one of the more interesting features is the ability to define properties that represent locations. The “GeoPoint” type lets you add a location to your model that can be used in a variety of ways. Let’s look at some simple examples demonstrating how you can add this to your own APIs.
Recently, we looked at how to use remote methods to expose custom logic as REST API endpoints in Loopback. That was pretty cool, but it just isn’t enough if we want to build a full-blown, production API. Even in a relatively simple case like exposing an inventory, if we threw a new endpoint at everything we’d very quickly end up with a poorly designed (not to mention ugly) API.
Luckily, Loopback provides a number of fine-grained ways to inject custom application logic into every level of our APIs. Let’s take a look at one of these options: remote hooks.
When we talk about LoopBack, we’re usually talking about rapid API generation. But behind the REST APIs is a full object-relational mapping (ORM) system that enables you to do all the standard create, read, update, and delete (CRUD) operations in your Node.js code. If you’re creating only an API, then this may not be terribly important to you. But if you are creating both an API as well as a “regular” web site, then being able to use the ORM features could be very handy. While this is documented well in the “Working with data” section of the docs, I wanted to create a simple demo so I could wrap my head around how it actually feels to work with the server-side functions. I discovered that it is—for the most part—pretty simple, but model relationships add a few wrinkles that you have to consider when working with data.
Compose APIs, Build, Deploy and Monitor Node
Install API Connect
$ npm install -g apiconnect
Create your API Connect project
$ apic loopback
Launch API Designer
$ cd your-project
$ apic edit
API Designer will run on your local browser
An IBM BlueMix account is required to use the Designer. Register for IBM Bluemix