By using IBM MobileFirst Platform Foundation HTTP adapters, you can send GET or POST HTTP requests and retrieve data from the response headers and body. HTTP adapters work with RESTful and SOAP-based services, and can read structured HTTP sources such as RSS feeds.
The retrieved data can be in XML, HTML, JSON, or plain text format.
The adapter is configured with XML to define the adapter properties and procedures.
Optionally, it is also possible to use XSL to filter received records and fields.
- Creating the adapter
- Adapter XML structure
- XSL transformation filtering
- Creating a SOAP-based service request
- Services discovery wizard
- Sample application
Creating the adapter
From the project's directory, use
mfp add adapter and follow the interactive instructions.
In MobileFirst Studio, create an adapter and select the HTTP Adapter type.
A standard HTTP adapter structure is created.
Adapter XML structure
Settings and metadata are stored in the adapter XML file.
You can use either the Design or Source editor in the Studio, or use your favorite XML editor to modify the adapter XML file.
To edit the adapter XML file, you must:
- Set the protocol to HTTP or HTTPS.
- Set the HTTP domain to the domain part of HTTP URL.
- Set the TCP Port.
Declare the required procedures below the connectivity element.
The service URL is used for procedure invocations.
Some parts of the URL are constant; for example, http://example.com/. They are declared in the XML file.
Other parts of the URL can be parameterized; that is, substituted at run time by parameter values that are provided to the MobileFirst procedure.
The following URL parts can be parameterized.
- Path elements
- Query string parameters
See the topic about "The connectionPolicy element of the HTTP adapter" in the user documentation for advanced options for adapters, such as cookies, headers, and encoding.
The mandatory parameters to call the procedure are
The procedure can be parameterized at run time.
To call an HTTP request, use the
Provide an input parameter object, which must specify:
- The HTTP method:
- The returned content type:
- The service
- The query parameters (optional)
- The request body (optional)
- The transformation type (optional)
See the topic about "WL.Server.invokeHttp" in the user documentation for a complete list of options.
XSL transformation filtering
You can apply XSL transformation to the received data, for example to filter the data.
To apply XSL transformation, specify the transformation options in the input parameters of the procedure invocation.
Creating a SOAP-based service request
You can use the
WL.Server.invokeHttp method to create a SOAP envelope, which can be sent directly.
To call a SOAP-based service in an HTTP adapter, you must encode the SOAP XML envelope within the request body.
WL.Server.invokeHttp(options) method is used to call a request for a SOAP service.
The Options object must include the following properties:
pathproperty: a service path
content(SOAP XML as a string) and
Services discovery wizard
With MobileFirst Studio, you can reduce development time by using the Discover Back-end Services tool in order to autogenerate adapters from the following services:
- IBM Business Process Manager
- Right-click the services folder in a MobileFirst project and choose Discover back-end services, followed by selecting a type of service.
- Add the service location to use and select the service that you want to add to the adapter.
- Repeat for each service that you want to add. The service will be added to the same adapter.
For more information, see the topic about generating adapters with the services discovery wizard, in the user documentation.
Click to download the Studio project.▲