Skip to main content

Setting up a Rest Endpoint

Setting up a REST Endpoint

Prior to this training, make sure you have Postman installed or are proficient in cURL.

Rest endpoints are one of the easiest ways to get data out of your app. It is a relatively simple process, although it should be noted that we have not sorted out integrating a Mendix API with Tyke. This will come at a later date, and documentation will be provided.

In your app explorer, right click and click create new > Published Rest Service, and navigate to it. Your screen should look like this:

Rest1.png

Creating endpoints is simple. First you need to make a resource, which is just a grouping for your rest calls, and will determine the first part of your url for the rest call. Click on the new button and this page should pop up:

Rest2.png

From here you can specify the base path of the endpoint. This will not create specific calls. It acts as a grouping. Now on the right of that click new again to make an actual call. You should see this page:

Rest3.png

On this page you can specify the path, method type, and the parameters for the microflow it will call. Normally these will be limited to strings, because you will need to be able to pass them in through your call. Your response type will be dictated by the microflow that the endpoint calls. I prefer to return JSON as a string, but you can use an export mapping with an object that you pass in.

The top of the page is where you configure the security and url for your rest call. We currently do not have a way to integrate tyke with Mendix, so it is recommended that you use username and password for your validation. Because we log in through CAS, users do not know the actual password for their Mendix account (we generate a random strong password on their initial login). We are going to create a manual API User for the purposes of calling your APIs.

Only System Administrators should be able to do the following

To start, create a User Role for API calls. When you assign permissions to it, make sure that you grant it permissions only to the microflows and rest calls for the rest service, and grant the entity access needed for that.

On a page, create a datagrid with that retrieves users. For the XPath Constraint, use the following.

[System.UserRoles/System.UserRole/Name = ‘YOURUSERROLE’]

Add a create button to your datagrid that calls a microflow. Have that microflow create a ‘user’ entity, and shows a page. On that page, allow users to specify the name of the API user. After they save, call another microflow.

Rest5.png

In this microflow, use the randomStringPassword java action from the Community Commons Module. You can shoes the limits on this action. Make sure you change the User to be associated to the API User role, and to have the new password you create. Show the password to the user after the creation, but DO NOT allow it to be seen any time after that. If they forget their password, they will need to reset the password.