Use the following steps to expose a REST API with predefined Payload and Consume a REST API with given payload.
- Create a mulesoft project called ConsumeRestAPI.
- Add HTTP listener to the flow.
- Add Connector configurations.
- Host - localhost
- Port - 8081
- Base Path - /
- Specify the path
- Path - /postrequest
- Go to MIME Type section
- MIME Type - application/json
- Go to Advanced section
- Allowed Method - POST
- Go to Metadata section
- Add metadata - Output:Payload
- Add
- Give a name - RequestPayload
- Select Type - JSON
- Example - Provide sample Json file.
- Select
- Add Logger
- Message - #[payload.elementname]
- Add Request - HTTP. To consume a target REST API.
- Configuration:
- Add
- Name : Target Name
- Base Path : /
- Protocol - HTTPS
- Host - target-host-name
- Port - 443
- Authentication
- Basic Authentication
- Username
- Password
- Request :
- Method : POST
- Path : REST API URI
- Body
- payload - You can modify the payload using DW.
- Add Transform
- Output
- output application/json
- ---
- payload
ReplyDeleteIt is so nice article thank you for sharing this valuable content
Mule Certification
Mulesoft Training in Hyderabad