Decoupling APIs
Introduction
Exposing view entities instead of the underlying persistable entity takes away the complexity of the underlying schema. This helps you prevent frequent API changes if the data model changes. It also allows you to consolidate data from multiple tabs in a single API.
Use Case
For this purpose of this use case, the following domain model is used:

For example, you want to make an API call that returns Products, and allows you to filter the results by Category.
Creating a View Entity
Create a single view entity and expose it as an OData resource. To do this, follow these steps:
- Open your domain model and create a view entity called ProductCategoryVE.
- Add the following query to the OQL editor:
SELECT
p.ProductId as ProductId
, p.ProductName as ProductName
, p.QuantityPerUnit as QuantityPerUnit
, p.Discontinued as Discontinued
, c.CategoryName as Category
, c.CategoryId as CategoryId
FROM Shop.Product as p
JOIN p/Shop.Product_Category/Shop.Category as c
-
Right-click this entity and select Publish in OData service. Name this service POS_ProductCategory.
-
Add
ProductId
as a key attribute, then click OK. -
In the Entity field, double-click the ProductId attribute.
-
Uncheck the box Can be empty, then click OK.
-
Run your app locally and test the functionality.