How to create a Mendix Module that returns Mock Data for my Search Interface?

1
I need to create a module that acts like it is consuming REST services and return a response in a json format like this:  {     "results": [         {             "title": " Object Title",             "type": "Generic Object",             "date": "01/07/2019",             "identifier": "123456",             "url": "http://example.tool.com/123456",             "source": "Tool"         },         {             "title": "Object Title",             "type": "Generic Object",             "date": "01/02/2003",             "identifier": "abc987",             "url": "http://example.tool.com/abc987",             "source": "Tool"         }     ],     "start": 0,     "end": 1,     "total": 2 }   Essentially this piece would be plugged into a bigger project/module later on, but for now I need to create fake data within Mendix as if I'm connected to a service of some kind. 
asked
4 answers
3

Abdulkareem,

This should be pretty straightforward.  Here are the steps you'll need to follow:

  1. Create a JSON structure with the JSON above
  2. Create an Export Mapping using the JSON structure you created
  3. While creating the Export Mapping, choose the option to Map Automatically.  This will create the Mendix entities you'll need
  4. Set permissions on the created entities so that the appropriate user roles can create these entities
  5. Next, create a microflow.  In your microflow, you will create the data you want to export into JSON.  Looks to me like you will have maybe 3 or 4 entities.  In the microflow, create the top entity (probably called Root), then create the next entity down in the structure and associate it to Root, then create the next entity down, etc.
  6. You can create as many of the bottom level entities as you want, these will populate the array in the generated JSON
  7. At the end of your microflow, add an Export with Mapping activity, pass the Root object you created and select the Export Mapping you created.  Store the output in a string variable and you'll have your JSON, to use as you please.

All told, this should be a 10 or 15 minute task.

Hope that helps,

Mike

answered
0

Mike, 

Thank you for the response. I couldn't find step 4 anywhere. Also, when I created Export Mapping and mapped them automatically, it generated only 1 entity for me (Root) instead of 3 when I did an Import Mapping! Lastly, Now that I'm on step 7, how can I view the results? Can I display them on a page somehow? 

 

Thanks

Kareem

answered
0

Mike,

Thank you, that was helpful. I do have a couple of questions if you don't mind. 

1- In the pop-up message, I'm not getting all of the JSON key values and I think it's because of my microflow logic. In step 5, can you explain what is meant to "create" my entities? I assumed that I needed to use the "create object activity" and create my 3 entities. However, my export to JSON activity only allows me to select one parameter (which is Root) and so the output is not complete. See attached.

Also, assuming I get the results I want which is the complete JSON returned, any suggestions on how to generate new mock up data every time I run my module? 

answered
0

Mike,

Thank you very much. It successfully worked. 

answered