API Developer
The logistics API provides resources for calculating shipping costs and locating the nearest store for pickup.

In this section you will configure the assembly for the shipping calulation resource. Your API assembly will call out to two separate shipping vendors and provide a consolidated response back to the consumer.

Create the Logistics API Assembly

  1. Click on the logistics 1.0.0 API to edit its definition.

  2. Switch to the Assemble tab and click the Create assembly button.

  3. Add an activity-log policy to the assembly pipeline.

  4. Configure the activity-log action to log the payload for the Content field.

  5. Add an operation-switch policy to the right of the activity-log step.

  6. The operation-switch editor will open with a single case, case 0, created by default.

  7. Next to case 0, click on search operations... to show the drop-down list of available operations.

  8. Select the shipping.calc operation.

  9. Click the + Case button to add a second case for the get.stores operation.

  10. Click the X to close the operation switch configuration editor.

    You should see two new processing pipelines created on your operation-switch step - one for each case:

Configure the shipping.calc Case:

This operation will end up invoking two separate back-end services to acquire shipping rates for the respective companies, then utilize a map action to combine the two separate responses back into a single, consolidated message for our consumers.

  1. Add an invoke policy to the shipping.calc case.

  2. Edit the invoke action with the following properties:

    Title: invoke_xyz

    URL: $(shipping_svc_url)?company=xyz&from_zip=90210&to_zip={zip}

    Stop on error: unchecked

    Response object variable (scroll to the bottom): xyz_response

  3. Hover over the invoke_xyz policy and click on the clone button to add another invoke action:

  4. Edit the new invoke policy with the following properties:

    Title: invoke_cek

    URL: $(shipping_svc_url)?company=cek&from_zip=90210&to_zip={zip}

    Response object variable: cek_response

  5. Add a map policy after the last invoke, then click it to open the editor.

  6. Click the pencil button at the top of the Input column, then click on the + input button.

    Enter the following input configuration:

    Context variable: xyz_response.body

    Name: xyz

    Content type: application/json

    Definition: #/definitions/xyz_shipping_rsp

  7. Click the + input button again to add another input. Specify the following input configuration:

    Context variable: cek_response.body

    Name: cek

    Content type: application/json

    Definition: #/definitions/cek_shipping_rsp

  8. Paste the same schema definition that was used for the previous input (for our lab purposes, the responses from the shipping service are in the same format, thus using the same schema)

  9. You now have two inputs assigned to the map policy:

  10. Click the Done button to return to the editor.

  11. Click the pencil icon at the top of the Output column, then click the + outputs for operation... and choose the shipping.calc operation.

  12. Set the Content type parameter to application/json.

  13. Click the Done button to return to the editor.

  14. Complete the mapping. To map from an input field to an output field, click the circle next to the source element once, then click the circle next to the target element. A line will be drawn between the two, indicating a mapping from the source to the target.

  15. Click the X to close the map editor.

    Your assembly policy for the shipping.calc operation is now complete.

  16. Save your changes.

Conclusion

Congratulations, you have just configured an assembly which calls two separate endpoints and aggregates data from each response into a single consolidated response!

Proceed to Using GatewayScript in an Assembly.