Define contacts API response codes

The following topic demonstrates how to define multiple response codes for the IMS phone book API methods. The following steps in this topic are optional.

Before you begin

Ensure your API project is open in the IBM® z/OS® Connect API editor. You can do this by double-clicking the package.xml file for your IMS contacts API project in the Project Explorer view.

Ensure that your phone book service is assigned to your GET and POST API methods.

About this task

In this step, you will define response codes with unique response data mapping for each of the GET and POST API methods.
Note: The response mapping is effective only if the request completes with a HTTP status code of 300 or lower.

Procedure

  1. In the API editor, for the GET method, click Mapping... > Define Reponse Codes to open the response details for the GET API method.
  2. Click Add Response
    The Add Response window opens.
  3. Specify a response code of 404, and specify the following rules:
    1. For Rule 1, specify IVTNO_OUTPUT_MSG/OUT_MESSAGE as the service field. Select Starts with for the comparison operator. Enter SPECIFIED PERSON for the comparison value. Click the Add Rule (Green plus icon) button to add a new rule, and specify the logical operator AND next to Rule 1.
    2. For Rule 2, specify IVTNO_OUTPUT_MSG/OUT_MESSAGE as the service field. Select Ends with for the comparison operator. Enter NOT FOUND for the comparison value.
    3. Click OK. Save your changes, click File > Save (Ctrl-S).
    Adding a 404 response.
  4. Define a unique response mapping for the 404 response.
    1. Click Mapping... > Open response 404 mapping next to the 404 response.
      The field mapping editor opens.
    2. Under the Body - response section, right-click each of the following fields and select Add Remove transform:
      • lastName
      • firstName
      • extension
      • zipcode
    3. Save your response mapping changes, click File > Save (Ctrl-S). Close the field mapping editor.
    Assigning a remove transform to the 404 response mapping.
  5. In the API editor, under the Responses section for the POST method, click the Add Response button.
    The Add Response window opens.
  6. Specify a response code of 409, and specify the following rule:
    1. For Rule 1, specify IVTNO_OUTPUT_MSG/OUT_MESSAGE as the service field. Select Contains for the comparison operator. Enter ENTRY EXISTS for the comparison value.
    2. Click OK.
    Creating a 409 response.
  7. Ensure response code 200 is set as the default response code for the POST method if it is not already set.
    1. Click the Response button for the 200 response code.
    2. Click Set Response 200 As Default
  8. Save your changes to your API project by Clicking File > Save (Ctrl-S).

Results

You have configured multiple response codes for your phone book API GET and POST methods, your GET method has also been configured with a unique response mapping. Your API is now ready to deploy.

Screen capture showing the final configuration of the POST and GET methods.