Thursday, 9 April 2020

Mulesoft REST API with POST Operation.

Use the following steps to expose a REST API with predefined Payload and Consume a REST API with given payload.


  1. Create a mulesoft project called ConsumeRestAPI. 
  2. 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
  3. Add Logger
    • Message  - #[payload.elementname]
  4. 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. 
  5. Add Transform
    • Output
      • output application/json
      • ---
      • payload

1 comment: