Simple REST PUT and PATCH operations - Mendix Forum

Simple REST PUT and PATCH operations


At the moment it tedious to implement a PUT or PATCH operation for a REST published service that behaves as it should be.

PUT: change all attributes of an object to the specified values. Non-specified attributes will be set to null values.

PATCH: only the specified attributes will be changed. Non-specified attributes will not be changed.

If you would like to implement this behavior, it requires a Java action or a lot of Microflow modeling depending on the number of attributes. Can this be made easier in Mendix as this is a quite basic functionality in REST APIs?

3 answers

Definitely! At one of our clients we also have difficulties in both publishing and consuming the PATCH operation. In fact, when omitting attributes you create a partial object, a concept the Mendix Platform doesn't support. In an import mapping, Mendix will automatically make a full object and set the missing attributes to empty. This causes that an empty valued attribute and a unchanged attribute are ambiguous. Also when using an export mapping: if an attribute is unchanged this can be omitted, but if it is set to empty it should be send along.


You implement PUT by using an import mapping with 'retrieve by microflow' instead of 'find by key'. The microflow does the following:

  1. It retrieves the object
  2. Updates the object, setting all mapped attributes to 'empty'
  3. Returns the object

The mapping then sets all attributes that are specified to the correct value.

It'a a good idea to improve this, you would like to be able to specify this behavior in the mapping without having to add a microflow for each mapping.

Import mappings have the behavior that you describe for PATCH. So what other work do you need to do for PATCH?


Hereby some definitions that might be relevant: