🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Rest Patch
This page was created by Stephanie on 2023-04-26. Last edited by Wikiadmin on 2026-07-29.

You can use RestPatch to update selected fields of an existing object through an MDriven REST endpoint; it is for developers exposing a ViewModel to REST clients.

RestPatch is not an OCL operator. In MDriven, it is the REST operation that maps to the HTTP PATCH method. A PATCH request updates only the fields included in the request. Fields that are not included remain unchanged.

For the complete endpoint format, ViewModel setup, request-body examples, and response details, see Documentation:OCLOperators RestPatch.

Before you send a PATCH request

Your target ViewModel must be exposed as a REST endpoint. Set the Eco.RestAllowed tagged value to True on the ViewModel, as described in Documentation:Span.Eco.RestAllowed. Without this setting, the ViewModel does not expose REST operations.

The ViewModel must be rooted on the domain class whose existing instances you want to update. Add the fields that clients may update as ViewModel columns.

For example, an ArticleViewModel rooted on Articles1 can expose a direct column mapping such as:

title : self.title

A client can then PATCH an existing article identified by its MDriven object ID. The ID has the form class ID!instance ID, for example 3!396.

Update selected fields

Send the fields to change as key-value pairs in the request body. MDriven updates the supplied fields and leaves the remaining exposed fields unchanged.

For example, a request that supplies only title updates the title but does not change content, author, or other fields omitted from the request.

PATCH http://localhost:8182/Rest/ArticleViewModel/Patch?id=3!396

 title = Updated Title

You can update multiple fields in the same request by including additional key-value pairs. See Documentation:OCLOperators RestPatch for the supported URL forms and request example.

Use direct mappings for fields you patch

Use a direct mapping when a field must have clear PATCH behavior:

title : self.title

A computed OCL expression can be useful for display, but its REST response contains the computed value rather than the underlying stored value. For example:

author : 'By ' + self.author

After a PATCH, this column returns a value such as By Ada. Keep update-oriented columns as direct mappings so that clients work with the intended field value.

Control server-side behavior with actions

PATCH can also execute actions in the root ViewModel class. MDriven applies values and executes actions according to the action column's position:

Action position in the root ViewModel class When it runs Example use
Before attribute columns Before sent values are applied Look up or prepare an object from request variables.
After attribute columns After sent values are applied Validate, calculate, or act on the updated values.

For example, an action placed after a title column can append text to the newly supplied title. If the action is placed before that column, the incoming title assignment occurs afterwards and replaces that action's change.

You can use the REST verb in ViewModel logic to make behavior verb-specific. For example, a read-only or disable expression can prevent an action from running for PATCH while permitting it for POST or PUT. This lets one ViewModel expose different behavior for different REST verbs.

See Documentation:Rest Post and Documentation:OCLOperators RestPost for the corresponding POST action behavior.

Response

A successful PATCH request returns 200 OK and the full updated ViewModel object as JSON. If a returned ViewModel column uses a computed expression, the response shows that computed display value; this does not mean that the stored value was changed to the display text.

Do not confuse REST PATCH with model patching

REST PATCH updates data in an existing object through a REST endpoint. It is different from patching a model on a Turnkey server, which reapplies model changes and restarts the type system. Model patching can reload data and clears transient data.

See also