Recommendations for integrating this data from a REST API

0
QuestionI have a question about handling data from a REST API I'm consuming using Mendix. I've considered two approaches: using the automatically created entity or creating a new entity and passing API data to it. Specifically, I'm wondering how to pull information from the API into the custom entity I created.
asked
1 answers
1

If you create your own entity in the domain model, you just need to map the REST response to it. In your Call REST Service action, set the response handling to use an import mapping, and in that import mapping you point the JSON structure elements to the attributes of your custom entity. Thats the standard approach and gives you more control over attribute types, associations, and what you actually persist vs what you ignore.


The auto-created entity from the Consumed REST Service document is handy for quick prototyping, but for anything real you usually want your own entity so you can add validations, associations to other parts of your domain model, and not be tightly coupled to the exact shape of the API response.


So the flow is: Call REST Service action returns JSON, you have a JSON Structure based on a sample response, you build an Import Mapping from that JSON Structure to your custom entity, and then in the microflow you get back your object populated with the data. From there you can commit it, enrich it, whatever you need.

answered