Publish Data to Other Mendix Apps Using an App Service (Deprecated)
1 Introduction
In this how-to, you will create an app in which you keep track of the inventory of a shop. This app makes the inventory available for use in other Mendix apps via an app service.
2 Creating the Domain Model
The domain model defines the products that you want the save and how you want to expose them.
To create the domain model, follow these steps:
-
In the domain model, create a persistable entity called Product with two attributes: Name (String) and Stock (Integer).
-
Create a non-persistable entity called PublishedProduct with the same attributes.
4 Creating Pages
To create pages that allows users to create, edit, and delete products, follow these steps:
-
Add a new page called EditUser.
-
Add a data view.
-
From the Connector, drag the Product entity onto to yellow [Unknown] bar.
-
On the dialog box that appears, click OK.
-
Open the Home page and add a data grid.
-
From the Connector, drag the Product entity onto to yellow [Unknown] bar.
-
On the dialog box that appears, click OK.
-
From the Project Explorer, drag the EditUser page onto the New button.
-
From the Project Explorer, drag the EditUser page onto the Edit [default] button.
5 Creating a Microflow
We will now create a microflow that retrieves all the products from the database and converts them to published products.
To create this microflow, follow these steps:
-
Add a microflow called PublishProducts.
-
From the Toolbox, drag a Retrieve activity into the microflow.
-
Double-click the Retrieve activity and select From database.
-
For Entity, select Product, then click OK.
-
From the Toolbox, drag a Create list activity into the microflow.
-
Double-click the Create list activity.
-
For Entity, select PublishedProduct, then click OK.
-
From the Toolbox (under Other), drag a Loop activity into the microflow.
-
Double-click the loop and for Iterate over, select ProductList, then click OK.
-
From the Toolbox, drag a Create activity onto the loop.
-
Double-click the Create activity and for Entity, select PublishedProduct.
-
Click New, and for Member, select Name.
-
For Value, enter $IteratorProduct/Name, then click OK.
-
Click New, and for Member, choose Stock.
-
For Value, enter $IteratorProduct/Stock, then click OK.
-
From the Toolbox, drag a Change list activity onto the loop
-
Connect the Create PublishedProduct activity to the Add to list activity.
-
Double-click the Add to list activity and for List, select PublishedProductList.
-
For Value, enter $NewPublishedProduct, then click OK.
-
Double-click the red end event and for Type, select List.
-
For Entity, select PublishedProduct.
-
For Return value, enter $PublishedProductList, then click OK.
6 Creating an App Service
You will use the microflow to create an app service that exposes the products to other apps. To accomplish this, follow these steps:
- In Project Explorer, right-click a module and choose Add > Published services > Published app service.
- For Name, enter Shop.
- Click Create version.
- Go to the Actions tab and click New.
- For Name, enter Products.
- For Microflow, select PublishProducts, then click OK.
- Go to the Settings tab and for Authentication, select Username and password.
- Go to the General tab and for Status, select Consumable, then click OK.
- A dialog box will ask whether you want to make this version available. Click OK.
7 Securing the App
Before you publish our app, you need to make sure it is protected with a username and password. To accomplish this, follow these steps:
- In Project explorer, double-click Project > Security.
- For Security level, select Prototype/demo.
- Click Edit module security.
- Go to the Page access tab and check all the checkboxes.
- Go to the Microflow access tab and check all the checkboxes, then click OK.
- Go to the Administrator tab.
- Type a password, and then click OK.
8 Publishing the App Service
You can now go ahead and deploy the app. This will publish your app service.