Module 8: Consuming Web Services

About

1.

Objectives

  • Consume web services that have an API (and connector) in Anypoint Exchange
  • Consume RESTful web services
  • Consume SOAP web services
  • Pass parameters to SOAP web services using the Transform Message component
  • Transform data from multiple services to a canonical format

Notes

Intro

Goal

  • Call an operation of an APi in Exchange
  • Call a RESTful web service
  • Call a SOAP web service

At the end of this module, you should be able to

  • Consume web services that have an API (and connector) in Exchange
  • Consume RESTful web services
  • Consume SOAP web services
  • Pass parameters to SOAP web services using the Transform Message component
  • Transform data from multiple services to a canonical format

Consuming web services that have an API (and connector) in Exchange

Topic video

  • Connectors in Anypoint Exchange

    • Many connectors in Exchange provide an easy way to make calls to APIs
  • Connectors and modules

    • Modules are extensions to the Mule runtime that you can use when building a Mule app

      • HTTP, Database, Salesforce, SAP, Slack, Validation, Java, and many more
      • Studio notifications for new version of used modules
    • Connectors are modules that connect to an external server

      • HTTP, Database, Salesforce, SAP, Slack
  • Connector types specify creator and support level

    • The type of selector is specified in its tags on Exchange e.g. community


      Exchange Connectors

  • Connector support levels


    Connector Support Levels

    • Tier 1: MuleSoft will isolate the problem and diagnose it
    • Tier 2: MuleSoft will find a workaround
    • Tier 3: MuleSoft will fix the code
  • Connectors are automatically generated for APIs added to Exchange

    • REST CONNECT is the tool that generates connectors for RESTful APIs

      • Resides in Exchange and automatically invoked when an API is added to Exchange
      • Works for both RAML 1.0 or OAS API specifications added to Exchange
      • Both Mule 3 and Mule 4 connectors are generated
    • You can use the connector in Anypoint Studio or Flow Designer
    • Download connectors from the download drop-down menu in Exchange


      Exchange Connector Download

  • Connectors in Anypoint Studio

    • Some modules are pre-installed in Studio: HTTP, Database, Salesforce, Validation, Java
    • Some modules are not pre-installed in Studio: SAP, Slack, Generated REST connectors
  • Adding connectors from Exchange

    • If connectors are not pre-installed in Anypoint Studio, you can search Exchange and add them to a project


      Adding Connectors from Exchange

  • Walkthrough 3-1: Consume a RESTful web service that has an API (and connector) in Exchange

    • Create a new flow to call the American RESTful web service
    • Add a REST connector from Exchange to an Anypoint Studio project
    • Configure and use a REST connector to make a call to a web service
    • Dynamically set a query parameter for a web service call

Consuming RESTful web services

Topic video

  • Consuming RESTful web services

    • First check and see if there is an existing Anypoint Connector in Studio or Exchange to connect to the service provider
    • If there is not, use the HTTP connector and its Request operation

      • Configure the operation and/ or global element configuration
      • Specify any headers, query parameters, or URI parameters to pass to the call
  • Walkthrough 3-2: Consume a RESTful web service

    • Create a new flow to call the United RESTful web service
    • Use the HTTP Request operation to call a RESTful web service
    • Dynamically set a URI parameter for a web service call
    • Add metadata for an HTTP Request operation’s response

Extras

  • Consuming Web Services Explained | Lightboard Series


    Consuming Web Services

    • Compare REST Connect connectors and compare them to using HTTP to invoke an API
    • The Control Plane’s Exchange provides the ability to document, and discover/ share RAML or OAS spec
    • In the background, the Control Plane will generate a REST Connect connector in Exchange, which can be used in Studio or Flow Designer to call the downstream API
    • APIs can still be called without the REST Connect connector, since it’s just an HTTP request, so you’ve options e.g. Use the HTTP Request connector or the REST Connect connector automatically generated from your API spec; it will give you the output structure and the underlying hints or DataSense in the IDE and it provides the URL and other elements you would have to manual add in HTTP Request, it also prefixes the errors with the name of the API. However, HTTP Request provides more advanced functionality such as timeouts and additional lower level HTTP things. Therefore HTTP Request connector is more powerful and the custom REST Connect connector is more convenient.

Consuming SOAP web services

Topic video

  • Consuming SOAP web services

    • First check and see if there is an existing Anypoint Connector in Studio or Exchange to connect to the service provider
    • It there is not, use the Web Service Consumer connector

      • Add the Web Service Consumer module to the project
      • Configure a global element configuration, which includes the location of the WSDL
      • Use the Consume operation
      • Select the SOAP operation to invoke
    • Passing data to a SOAP web service

      • Use the Transform Message component to pass arguments to a SOAP web service

        • Could also be used to set the required input payload to the SOAP operation
      • When you add it before the Consume operation, DataSense is used to create metadata for the input that includes the arguments
    • Walkthrough 3-3: Consume a SOAP web service

      • Create a new flow to call the Delta SOAP web service
      • Use the Web Service Consumer connector to call a SOAP web service
      • Use the Transform Message component to pass arguments to a SOAP web service

Combining data from multiple services

Topic video

  • Combining data from multiple services

    • Data from different services is pretty much always going to be in different formats
    • To combine the data set, you need to transform each of them to a canonical, or standard format
  • Walkthrough 3-4: Transform data from multiple services to a canonical format

    • Define a metadata type for the Flight Java class
    • Transform the results from RESTful and SOAP web service calls to a collection of Flight objects

Summary

To consume a web service, first look to see if it has a connector in Anypoint Exchange

  • Easiest way to consume a web service
  • Connectors for APIs specifications added to Exchange are generated automatically by REST Connect

Use the HTTP Request operation to consume any REST web service

  • With or without URI parameters and query parameters
  • With or without a RAML definition

Use the Web Service Consumer connector to consume any SOAP web service

Use the Transform Message component to pass arguments to SOAP web services

Test your knowledge

What file type is required to configure a Web Service Consumer to consume a SOAP web service?

  • WSDL

What is the process to create a connector using REST Connect?

  • Design the API in Design Center and publish the API to Exchange

How are query parameters dynamically passed to an outbound REST request using an HTTP Request operation?

  • As query parameters in the HTTP Request operation

Refer to the exhibit. The flow calls a SOAP endpoint using the Consume operation of the Web Service Consumer. The SOAP service has a requried iniput parameter. What event processor can be used to build the SOAP envelope with the required argument to pass to the SOAP service?

  • Transform Message

An HTTP Request operation returns a JSON array of objects. In the Transform Message component, what is the process to convert the array of objects to an array of custom Java Account objects?

  • Add the Account object metadata to the output and use the drag-and-drop feature to transform the incoming JSON data

Anki

References


  1. . “Module 8: Consuming web services”. Available at: . (Accessed: [2025-03-09 Sun 20:44]). ↩︎

Random Posts