Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of the Application model in Loopback

In a Loopback application, there's mention of a built-in Application model.

This page says "contains metadata for a client application that has its own identity and associated configuration with the LoopBack server."

When clicking through the referenced page it further elaborates with this:

Application model

Use the Application model to manage client applications and organize their users.

The default model definition file is common/models/application.json in the LoopBack repository.

The first link in that paragraph I think is incorrect as it refer to the Express application wrapper, rather than an instance of the model.

The second link details the attributes of the model. There's mentions of things like ownership, realms (which is mentioned in the context of Users), and various other settings.

The Application model is mentioned in a few places in the documentation but it doesn't really explain how to use it.

How would you access the Application model in an app?

Where are all the attributes defined in your app?

Can you have more than one Application instances, and why?

Hope this isn't taken as a subjective topic, I'm really just after better documentation on the topic.

like image 611
Ben Avatar asked Dec 11 '15 04:12

Ben


1 Answers

The Application model in LoopBack is meant to act similarly to the User model, but instead of individual users using the API, apps can also gain access to the API. An example would be if you had a payment API. You might want to grant access to users so they can transfer money to each other, but you might also want to grant access to a web app (online store) or provide a payment service to mobile apps.

I suggest going into server/model-config.json and adding the following:

"application": {
  "dataSource": "db",
  "public": true
}

You can then open up the component-explorer and play around with API endpoints for the application model. Here are the API docs

(I also suggest you open up an issue on loopback requesting better documentation.)

like image 189
richardpringle Avatar answered Sep 28 '22 08:09

richardpringle