This blog demonstrates the use of readUrl function
How to read a file using read Url function.
- readUrl() is part of core module. It takes three parameters as input& returns the content of the file.
|The URL string to read. It also accepts a classpath-based URL.||A supported format (or MIME type). Default: application/dw.||Optional: Sets reader configuration properties.|
Create a new mule application by clicking on File->New->Mule Project
Name the project appropriately and select the mule runtime as 4.3.0
The new project gets created successfully.
Step 4 :
Create a json file with name student.json in src/main/resources as shown below. Right click on src/main/resources. Go to New->File->student.json and paste the data given below in json file.
“Studentid” : “101”,
“Studentname” : “Sumit”
New file gets created as shown below. We are going to read this file using readUrl().
Step 6 :
Drag & drop http-listener & transform message component from Mule Palette in the Mule Configuration file.
Step 7 :
Configure http-listener with appropriate hostname ,port & path.
Add the Dataweave code to read the file as shown below:
Step 9 :
Save all the files. Right click on mule app->Run As->Mule Application
The mule app gets deployed and a success message is displayed in console as shown below:
Go to postman. Create a new request & populate the following details:
HTTP Method: GET
Click on Send button on the postman.
Step 13 :
We get a success response with http status code as 200 & response body as the content from the file.