How to make the most out of Mendix’ native REST publish functionality

Willem van Zantvoort
Mendix Community
4 min readApr 28, 2020

--

One of the most requested features for the Mendix Modeler has been released and is under continuous improvement: native published REST services! In this blog, I want to explain what this addition to Mendix’s toolkit does, why you should use it and how.

Just as Mo Connected said five years ago: everybody and everything needs to be connected. Even though Mo is talking about mobile phones and people, the same can be said for apps. With the amount of data we are producing nowadays, we would be crazy not to share it with other apps so they can improve their use even further.

This is exactly what the newly published REST services enable us to do. Of course, this was already possible with published web services and the REST module, but us Mendix developers love it when awesome features become available natively within the Mendix Modeler. Especially one as easy to use as this!

We can now create a published REST service and define the desired endpoints and operations in no time. Security is being handled by Mendix and on top of that, we automatically get Swagger documentation to share with our customers, partners, and colleagues. It is functionalities such as these that make me really happy!

Having played with these services a bit, I would like to use this opportunity to give you some pointers on how to make the most out of your published service. In order to place these tips in a context, we’ll make use of an example service about fruit.

1. Use the HttpRequest body attribute to receive data in your POST operations.

Try to limit the use of operation path/parameters to identifiers only, because of the data that is visible in the URL and your outgoing request. It’s OK to use parameters in the operation path for GET or DELETE operations, but avoid these in your POST operations.

OK: GET -> localhost:8080/rest/fruit-v1/fruit/banana

Not OK: POST -> localhost:8080/rest/fruit-v1/fruit?name=banana&color=yellow

2. Use an Import mapping to parse a request’s body.

As of Mendix 7.11, you can use the HttpRequest as input in the Import from JSON activity.

3. Think of backward compatibility. You can, for example, create a new domain model for each version so not everyone needs to update their services the moment you deploy a new version.

Also, add the version to your service name, so it will become visible in your documentation. As of Mendix 13.1 versioning is incorporated in the Modeler.

4. Create generic response flows for each type of error such as 422 and 404 and success messages such as 200 and 201. This will enable you to quickly build validations and error handling.

No one likes consuming web services with crappy error handling. Don’t make the same mistake!

5. Be sure to set the HttpHeader when sending responses!

Without this, the receiving end will not know what kind of content you are providing them with. In some cases, this will lead to errors.

If you also want to publish your own services, take a look at my YouTube tutorial for more information, download my example project from the Mendix AppStore or find it on Github. For some best practices regarding a REST API take a look at this website or this article.

Other great resources are:

  1. https://docs.mendix.com/howto/integration/consume-a-rest-service
  2. https://docs.mendix.com/refguide/call-rest-action
  3. https://video.mendix.com/watch/RMw45uwCAjYi2ej7ykAseu How to Mendix — consume rest service
  4. https://gettingstarted.mendixcloud.com/link/path/44/Importing-and-Exporting-Your-Data
  5. https://ww2.mendix.com/expert-webinar-REST-Services.html
  6. https://ww2.mendix.com/Expert-Webinar.REST-Integration.html

Want to get started with Mendix yourself? Sign up here!

--

--