Friday 18 May 2018

IBM API Connect - More on API consumption

Following on from an earlier post: -


I've been happily consuming an API from IBM API Connect ( on cloud ) using a SOAP client ( SoapUI ), sending in SOAP: -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://www.ibm.com/rules/decisionservice/HelloWorldProject/HelloWorld">
   <soapenv:Header/>
   <soapenv:Body>
      <hel:HelloWorldRequest>
         <!--Optional:-->
         <hel:DecisionID>?</hel:DecisionID>
         <hel:request>David M M Hay</hel:request>
      </hel:HelloWorldRequest>
   </soapenv:Body>
</soapenv:Envelope>


to get back SOAP: -

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:ds="http://www.ibm.com/rules/decisionservice/HelloWorldProject/HelloWorld"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<HelloWorldResponse
xmlns="http://www.ibm.com/rules/decisionservice/HelloWorldProject/HelloWorld">
<DecisionID>?</DecisionID>
<response>Hello David M M Hay</response>
</HelloWorldResponse>
</soapenv:Body>
</soapenv:Envelope>


I wanted to go a little further, and also consume the same API using a command-line, having subscribed to the API via the APIC Developer Portal.

To do this, I hit up the Developer Portal: -

and registered myself as a new developer ( trick is to use a DIFFERENT email address to avoid getting confused between the admin and developer roles ).

Having created an Application ( App ), I then navigated into my chosen API Product: -


and subscribed to the API.

I then grabbed my Client ID: -


Having created a XML snippet containing the SOAP request: -

vi canary.xml 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:can="http://Canary">
   <soapenv:Header/>
   <soapenv:Body>
      <can:operation1>
         <input1>David M M Hay</input1>
      </can:operation1>
   </soapenv:Body>
</soapenv:Envelope>


I finished by involving the Canary API: -

curl --insecure --header "Content-Type: text/xml;charset=UTF-8" --header "X-IBM-Client-Id: b0aca626-ceed-4f21-b7d0-a8c725076659" --data @canary.xml  https://api.eu.apiconnect.ibmcloud.com/foobarukibmcom-foobar/sb/CanaryHttpService

To break the command down, we have: -

Parameter Value Why
   
--insecure By default, every SSL connection curl makes is verified to be secure. This option allows curl to proceed and operate even for server connections  otherwise  considered insecure
--header Content-Type: text/xml;charset=UTF-8 The service expects XML
--header X-IBM-Client-Id: b0aca626-ceed-4f21-b7d0-a8c725076659 To set the client ID
--data @canary.xml The reference to the XML file containing the SOAP envelope
  https://api.eu.apiconnect.ibmcloud.com/foobarukibmcom-foobar/sb/CanaryHttpService The URL of the API, as exposed via the Developer Portal ( and hosted on the Gateway )

For the record, this is using the native macOS version of curl 

ls -al `which curl`

-rwxr-xr-x  1 root  wheel  185104 28 Mar 05:02 /usr/bin/curl

Final thought, this gave me the heads-up on using —header X-IBM-Client-Id : -



No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...