Single resource having different data format and data type in RAML
Author: Abhishek Bathwal
This blog will showcase how a Single resource in RAML can have different data formats and different data types.
RAML:
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.
DataType:
JsonOne: JsonTwo:
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.
Flow:
Note: Just replace the logger with a Transform message to display the payload as response.
Testing:
Will be using postman to test the application.
Json Format:
- 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:
XML Format:
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