Part of Four of the API Development Series. In this part we will show how to create simple definitions in API Connect and use the Mapping Policy to map between them.

Introduction

Start by creating a new API liked we did in part 1 only with this endpoint. http://apic-test-app.eu-gb.mybluemix.net/api/payment

The sample below can be used,

swagger: '2.0'
info:
  version: 1.0.0
  title: paymoney
  x-ibm-name: paymoney
basePath: /paymoney
x-ibm-configuration:
  properties:
    target-url:
      value: 'http://apic-test-app.eu-gb.mybluemix.net/api/payment'
      description: URL of the proxy policy
      encoded: false
  cors:
    enabled: true
  gateway: datapower-gateway
  type: rest
  phase: realized
  enforced: true
  testable: true
  assembly:
    execute:
      - proxy:
          title: proxy
          version: 1.0.0
          verb: keep
          target-url: $(target-url)
  application-authentication:
    certificate: false
paths:
  /:
    post:
      responses:
        '200':
          description: success
          schema:
            type: string
      consumes: []
      produces: []
securityDefinitions:
  clientID:
    type: apiKey
    in: header
    name: X-IBM-Client-Id
security:
  - clientID: []
schemes:
  - https

This Service takes in a payload in the format.

{
  "toId":"1001",
  "fromId":"1002",
  "amount":100
}

We will modify the API to accept the following payload

{
  "FromAccountNo":"1001",
  "TargetAccountNo":"1002",
  "Amount":100
}

Steps

  1. Go to the Design View

  2. Go to Definitions

  3. Click on Add

  4. Enter the following parameters

    Name : IntialRequest
    Description : This is the payload schema for the data passed into the API

  5. Press Add
  6. Enter the following details
    Property Name : FromAccountNo
    Property Type : String
    Property Example : 1001
    Property Description : The account number to take the money from.

  7. Press Add

  8. Enter the following details
    Property Name : ToAccountNo
    Property Type : String
    Property Example : 1002
    Property Description : The account number to put the money from.

  9. Press Add

  10. Enter the following details
    Property Name : Amount
    Property Type : float
    Property Example : 100
    Property Description : The amount of money to move

  11. Press Save

  12. Now we will create the definition for the Service Request.
    Click on Add

  13. Enter the following parameters

    Name : ServiceRequest
    Description : This is the payload schema for the data passed into the Downstream Service

  14. Press Add

  15. Enter the following details
    Property Name : fromId
    Property Type : String
    Property Example : 1001
    Property Description : The account number to take the money from.

  16. Press Add

  17. Enter the following details
    Property Name : toId
    Property Type : String
    Property Example : 1002
    Property Description : The account number to put the money.

  18. Press Add

  19. Enter the following details
    Property Name : Amount
    Property Type : Number
    Property Example : 100
    Property Description : The amount of money to move

  20. Press Save

  21. Go to Path

  22. Click on /

  23. Click on Post

  24. Click on Add in the Parameters Section

  25. Enter the following details
    Required : True
    Name : Request

    Located in ; body
    Type : IntialRequest
    Descrioption : JSON Payload container details on the acounts to move money from and two, and the quantity.

  26. Press Save

  27. Goto Assembly

  28. Drag a Parse Policy onto the start of the flow. The parse policy is required to turn the input message from a buffer into an Object.

  29. Drag a Validate policy and place it after the Parse policy. We want to validate the payload prior to invoking the DownSteam service.

  30. Click on the Validate policy and select the following

  31. Drag a Map Policy after the validate and before the Invoke and configure it like below.

  32. Set the Input to the following

  33. Set the Output to the following

  34. Link up the parameters, dragging the left circle to the corresponding right circle for each parameter.

  35. Save and Publish the API,

  36. Invoke it as described in part 1