Build a rest service using mendix

I am trying to build a mendix rest service to return me a json object with the data that I need. I want to do this using mendix and not needing to call an external one.  I want this rest service to return me a JSON object or alternatively read from a .json file on my computer and serve that data in mendix. For example the “MockHRService” in one of the tutorials reads from a “MockData.json” file and later returns that data to be used – hitting the endpoint in the browser will return an xml format of the data. I tried to copy this like for like and I unable to reproduce this and cannot figure out why the data in my “MockData.json” is not being returned? Instead when I hit the endpoint for my rest service, in the browser I get: “This XML file does not appear to have any style information associated with it. The document tree is shown below.”   When I put a breakpoint in the microflow, then list is empty.  
2 answers

If the list is empty before it is passed to the mapping, then you will get an empty result.

Just for a rest-service practice: right-click on any entity in your domain model and select "Expose as REST service”.


I think you would be better off using something like .

Otherwise, do something like this:

- Create new entity with generalization of FileDocument

- In your microflow which is used by rest service operation, create new object of this filedocument specialization

- Import CommunityCommons module from the appstore in to your project

- Place Java action GetFileContensFromResource in your microflow and specify parameters (your newly created document and filename of the document which resides in your resourcefolder

- Place Java action after StringFromFile and input your created document entity.

- Set the return parameter of the microflow, the red endpoint to the string of the last Java action.