Working with Geographical Data in your API

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.

Read more

Applying Custom Logic in Phases: Using Remote Hooks in LoopBack

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.

Read more

Working with LoopBack’s Object-Relational Mapping (ORM) System

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.

Read more

Remote Methods in Loopback: Creating Custom Endpoints

One of the nicest features of Loopback is the ability to quickly expose existing datasources (MySQL, MongoDB, Cloudant, etc.) as REST APIs with standard CRUD (create, retrieve, update and delete) support. But let’s be honest, that’s not really going to cut it. We need to do more than expose data. We need to extend these basic endpoints to expose additional functionality and application logic, while keeping the design of our API as clean as possible.

This is one area where the flexibility of Loopback really shines. Enter remote methods.

Read more