Use of the Application model in Loopback
Asked Answered
A

1

6

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.

Aldercy answered 11/12, 2015 at 4:47 Comment(1)
Good question - I've wondered the same thing myself. I know their documentation is a WIP, I see people working on it all the time.Staggers
M
7

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.)

Manslayer answered 18/8, 2016 at 17:15 Comment(1)
Thanks, I think that starts explaining some of it :)Aldercy

© 2022 - 2024 — McMap. All rights reserved.