Search code examples
node.jsloopbackjsstrongloop

Using Loopback datasources & models without loopback


I envision loopback's datasources & models as a useful tool for consuming an API, not just for automatically creating a REST API.

Pretend I'm using Spotify's API. I want a command line application that looks up user information on Spotify. I could write loopback models to consume say /v1/albums.

I'm hoping I can create an Album model and use it like Album.find('Thriller');.

What I don't want is to create a REST API. I just want a better language to consume other people's APIs such as Facebook or Instagram.


Solution

  • A LoopBack model is just a config file and a collection of functions in a model file. All of the endpoints are generated by LoopBack itself, and as such not very helpful by themselves. That said, you can generate a swagger spec for each of your models with the explorer component (installed by default when you use the scaffolding CLI: slc loopback).

    Simply start up your LoopBack application, then navigate to:

    http://localhost:3000/explorer/resources/MyModels
    

    You could then use the swagger spec in any framework that supports that standard.