Virtualizing a REST API without recording or synchronization
You can virtualize REST APIs by using the Recording Studio, or by synchronizing WADL, Swagger, or RAML documents. When none of these options is available, you can still manually virtualize REST APIs that use path parameters.
Consider the following scenario: You have the description of a REST API that uses path
parameters, but no formal definition (WADL, Swagger, or RAML) is available. However, you want to
build stubs for the API so that you can test the clients against those stubs when the real service
is being implemented. With
Rational® Integration
Tester you can
virtualize the REST API manually, that is, without recording, or when you have no WADL documents, Swagger definitions, or RAML definitions
to synchronize. This topic provides an overview of the virtualization process by using the phonebook
sample.
- Open the following URL:
https://mydefaultserver:5443/RTCP/examples/
. Note that there are five requests under Phone Book. - Create web URL schemas for the URL patterns used:
/RTCP/examples/phonebook/api/
and/RTCP/examples/phonebook/api/{id}
. For details, see Creating a Web URL schema.- For both the URL patterns, click the green plus icon (Add new URL
template), add a path segment of type Literal with the value
/RTCP/examples/phonebook/api/
. - For the second URL, also add a new path segment of type Parameterized with the value id, which will be the name of the parameter.
- Change Type to Integer.
- Enter meaningful names for the URLs, for example, phonebook and entry respectively, because you will refer to them by these names in the remainder of this procedure.
- For both the URL patterns, click the green plus icon (Add new URL
template), add a path segment of type Literal with the value
- In the Architecture School perspective, create a transport for the host that is running on port 5443, as applicable. For details on how to create an HTTP transport, see Creating HTTP transports.
- Create operations as recommended in the following table. See Creating an operation.For each operation, open the operation editor by double-clicking it and do the following steps:
- Go to the Message Exchange Pattern tab.
- Select the transport you created in Step 3.
- Select the Web URL schema identified in the first column of the following table. Use the names you entered for them in Step 2 for selection. Also select a JSON schema which is needed for the response.
- For HTTP Method, use the value identified in the first column of the table.
- Open the Stub tab.
- Select the transport you created in Step 3.
- On the Property Filters tab, select the Filter resource path check box.
- In the Resource Path field, enter
/RTCP/examples/phonebook/api/
. The Resource Path field never contains path parameters because these are identified in the selected Web URL schema. - For the subpaths field, select values from the second column of the table.
- Ensure that the Filter HTTP method field is set to the HTTP method identified in the first column of the following table.
For details on how to change the Message Exchange Pattern of an operation, see Changing the message exchange pattern for an operation. For details on how to use resource paths and sub paths, see Changing the stub page for an operation.GET /RTCP/examples/phonebook/api/
The operation does not accept subpaths. GET /RTCP/examples/phonebook/api/{id}
The operation (created by using a REST schema) accepts only subpaths. POST /RTCP/examples/phonebook/api/
The operation accepts only the exact path as specified. PUT /RTCP/examples/phonebook/api/{id}
The operation (created by using a REST schema) accepts only subpaths. DELETE /RTCP/examples/phonebook/api/{id}
The operation (created by using a REST schema) accepts only subpaths. - Create a multi-operation stub for all of (or a subset of) the operations that you created in the previous step. For details, see Stubs with multiple operations.
You can use the stubs for the phonebook example by using the URL that is reported in the stub
output (for example, http://10.0.0.1:51234/RTCP/examples/phonebook/api/
) or by
using a Configuring a HTTP(S) reverse proxy or TCP port forwarding rule. Review the various responses you have configured in the stub depending on whether the
id
path parameter is present in the requested URL or not. For details on the ways
in which you can send requests to a stub, see Virtualizing HTTP.