Author: Abhishek Bathwal
This blog will showcase how a Single resource in RAML can have different data formats and different data types.
Created a RAML with Resource as Mule and having two data format application/json and application/xml.
- application/json — It contains two data types JsonOne and JsonTwo.
- application/xml — No particular data type is defined so it can accept any type of xml input.
JsonOne: Contains two fields Description and type and both the fields are mandatory.
JsonTwo: Contains Only field Name and that is also mandatory.
Finally the RAML Project will look like below:
The next step will be to create the flow from the RAML Specifications:
Import the RAML to the Mule application and create the flow out of it.
Note: Just replace the logger with a Transform message to display the payload as response.
Will be using postman to test the application.
- First Datatype:
When provided the Correct field and tested then it returns the correct response:
When provided Incomplete field it returns error. Not passed the field type:
2. Second Datatype:
When provided correct field it returns correct response:
Incorrect field provided:
It accepts any type of field as no specific data type is defined for it.
So it verifies that a single resource can have multiple data formats and multiple data types.
Reference: MuleSoft Partner