Consumed REST Services (Beta)
Introduction
Use the new Consumed REST Service document to send REST requests from Mendix Studio Pro. With this feature, you can build, test, and create data structures to store your requests.
This feature is supported for Mendix Studio Pro 10.6 and above.
Use Cases
You can use this Consumed REST Service document to do the following:
- Consume a REST Service
- Configure
GET
,POST
,PUT
,PATCH
, andDELETE
requests - Create entities directly in the domain model
- Send REST requests through a microflow
Limitations
-
PATCH
methods are only supported for Mendix Studio Pro 10.7 and above. -
PUT
methods are only supported for Mendix Studio Pro 10.8 and above. -
DELETE
methods are only supported for Mendix Studio Pro 10.9 and above. -
To use the request response to create a data structure in your domain model, the response data should be in JSON format. Other formats, such as XML, are currently not supported.
-
If you are debugging a running Published REST Service in the same app as your Consumed REST Service document, a deadlock could occur when sending the request. Wait until the timeout occurs (default: 300 seconds) for Studio Pro to respond again.
Prerequisites
- Studio Pro 10.6 and above
- Familiarity with HTTP request methods
Add the Consumed REST Service Document
Download Studio Pro and add the Consumed REST Service document to your app. To do this,
- Right-click the module you want to add the Consumed REST Service document to.
- Select Add other > Consumed REST service.
- Name the service and click OK.
Configuration
Use the Consumed REST Service to configure a GET
, POST
, PUT
, PATCH
, or DELETE
request for your app.
Basic Configuration
Create a GET
, POST
, PUT
, PATCH
, or DELETE
request to send data to your server by doing the following:
-
In the General field, name your request.
-
In the Method & URL field, use drop-down to select the HTTP method you want to use.
-
Add an endpoint and click Send.
-
Click Configuration & authentication.
-
Add a Base URL to use the same URL across all requests in this consumed REST Service document.
-
Select an authentication method. For more information, see Authentication methods.
-
Click Send.
You can visualize your request in the Response data tab, then use the response to create an entity in the domain model.
Authentication Methods
You can configure basic authentication to use for all requests in your document. Authentication is not required but can be added if needed. To add basic authentication, do the following:
-
Click Configuration & authentication.
-
Under Authentication method, click the drop-down and select Basic authentication.
-
Select a constant or create a new one for your username and password. To create a new constant, follow these steps:
- Next to Username or Password, click Select > New.
- Name the constant and click OK.
-
Add any additional information needed and click OK > OK.
Adding Parameters
Parameters are fully supported in the path and query part of the URL and in the header value. They are defined within curly brackets. For example, in the URL, defining numbers
as parameter would be http://numbersapi.com/{numbers}
. All parameters must be added to the Parameters grid and match what is present within the curly brackets.
To add a parameter, follow these steps:
-
Open the Parameters tab and click Add.
-
Name your parameter, add a test value, and click OK.
-
To test the parameters, click Send.
Adding Headers
You can add a header for any HTTP request you have specified in your document. To add a header, do the following:
-
Open the Headers tab and click New.
-
In the Key field, click the drop-down and choose from the list of the most commonly used HTTP headers. You can also create a custom header by selecting Custom and adding in the value.
-
Click OK. To test the header, click Send.
Adding a Request Body (for POST, PUT, and PATCH requests only)
POST
, PUT
and PATCH
requests support JSON strings as a request body. Add the JSON body snippet to your request by doing the following:
-
Click the Body tab and add your JSON string.
-
To validate the input, click Send.
-
If you want to use the newly-created JSON string as an entity in your domain model, click Use JSON Snippet. The body string can be viewed in the Body structure tab.
-
The entity name is prefilled, but you can change it to a custom name. To create an entity, click Create Entity > OK. Click Show to view the entity in your domain model.
Creating an Entity from the Response
You can check the response of your request in the Response data tab.
If you want to use the response to create an entity in your domain model, navigate to the Response structure tab, which displays a preview of the response data.
The entity name is prefilled, but you can change it to a custom name. To create an entity, do the following:
- Click Create Entity > OK.
- To view the entity in your domain model, click Show.
Using a REST Request in a Microflow
To select a request in the microflow, complete the following steps:
- Create a new microflow and drag the Send REST request activity into it.
- Double-click the activity and click Select to choose the request you want to add, then click Select > OK.
If you have defined parameters in the request, they will be added to the activity. Click Edit to change the parameter in the microflow. The parameter values in this activity are used by the runtime instead of the test value defined in the request.