RestPatch allows you to update fields on an existing object via a REST API call in MDriven. It maps to the HTTP PATCH method and is enabled on a ViewModel when Eco.RestAllowed is set to True.
URL Format
http://<host>/Rest/<ViewModelName>/Patch?id=<objectId>
Example:
http://localhost:8182/Rest/ArticleViewModel/Patch?id=3!396
or
http://localhost:8182/Rest/ArticleViewModel/Patch/3!396
Where 3!396 is the MDriven object ID (class ID + instance ID).
Request Body
Send the fields you want to update as key value pairs in the request body. Only the fields you include will be updated other fields are left unchanged.
Example using form-data in Postman:
| Key | Value |
|---|---|
| title | Updated Title |
Multiple fields can be updated in a single request by adding more key-value pairs.
Response
On success the endpoint returns 200 OK with the full updated ViewModel object as JSON.
Example response:
The response will reflect thecomputed value, not the raw stored value. In the example above, patching title with "Updated Title" would return "Updated Title" in the response. This is expected behavior the underlying data is updated correctly, the display expression is just applied on top.
Setting Up a REST Endpoint
Step 1: Define Your Domain Class
Before creating a ViewModel, you need a domain class in the MDriven Designer that represents the data you want to expose. In this example that is the Articles1 class, which has attributes like author, title, content, publishedAt, and urlToImage.
You can see the full model in the designer Articles1 sits at the center, connected to Source1 via a source association, and to APIResult via an articles association.
Step 2: Create a ViewModel and Root It to Your Class
In the ViewModel Editor, create a new ViewModel and set its Class to the domain class you want to expose in this case Articles1. This is done in the Properties panel on the right side of the ViewModel Editor.
<Name: ArticleViewModel Class: Articles1
This "roots" the ViewModel to Articles1, meaning the REST endpoint will operate on instances of that class.
Step 3: Add Your Fields
Add the attributes you want to expose as columns inside the ViewModel. For example:
<title : self.title publishedAt : self.publishedAt content : self.content author : 'By ' + self.author urlToImage : self.urlToImage source : 'From: ' + self.source.name
Note: If a field uses a computed OCL expression like
'By ' + self.author, the REST response will return the computed value, not the raw stored value. Keep fields as direct mappings likeself.titleif you want clean PATCH behaviour.
Step 4: Enable Eco.RestAllowed via Tagged Values
This is the key step that exposes the ViewModel as a REST endpoint.
- Click Tagged values in the top-right of the ViewModel Editor
- In the Tagged Values dialog, you will see a Value Store at the bottom listing all available tags
- Add the following tags by selecting them and clicking Add This:
| Tag | Value |
|---|---|
Eco.RestAllowed
|
True
|
Setting Eco.RestAllowed to True is what registers the ViewModel as a REST endpoint. Without this, no REST operations (GET, PATCH, POST, DELETE) will be available on the ViewModel.
Step 5: Verify the Endpoint
Once the app is running, your endpoint is available at:
http://<host>/Rest/<ViewModelName>/
For the ArticleViewModel example:
http://localhost:8182/Rest/ArticleViewModel/
From here you can perform REST operations see the RestPatch section above for how to update objects via this endpoint.
