Sidebar

REST Inference

This brief tutorial will walk you through the schema inference function.

We'll start out by creating a new project, and adding a REST service, without an initial WADL file.

After sending the request, we can then use the responses to build our schema.

Demo Request

To demonstrate the principles we will use a demo request from the Flickr REST example .

https://www.flickr.com/services/rest/?method=flickr.test.echo&format=rest&foo=bar&api_key=d6c7b624b138bcb07a2e2c736aefeb65

The request (when successful) returns a response in the following format:

<rsp stat="ok">
    <method>flickr.test.echo</method>
    <format>rest</format>
    <foo>bar</foo>
    <api_key>9e5f204388e9d6070b6b1423876be728</api_key>
</rsp>

Note: The API key changes, so you may need to visit the Flickr REST demo site and get an up to date API key.

Creating The Project And Service

Getting the request into a REST project is easy:

  • Select File | New | Functional Test.
    New
  • Select the URL option.
    Choose URL
  • Paste the URL mentioned above and click Next.
    Url
  • Ready! API will offer you to run the test, or create a data-driven test. Close the dialog, since we do not need either option yet.

The project is created and added to the workspace:

Project created

The parameters from the request URL is extracted automatically, and can be viewed in the form editor.

Request And Response

Now we have a request to work with:

Parameters

The request holds all the parameters defined in one of its ancestors. The parameters have been pre-populated using the default values.

We haven't sent the request yet, so the response is blank:

Parameters

Schema Tab

The REST response view has a tab at the bottom called “Schema”. This is the inferred schema inspector.

  • Open the Schema tab.

Parameters

No information has been logged yet.

Normally, we would want the process of resolving schema conflicts to be automated. But for demonstration purposes we will take the manual route this time:

Parameters

  • Make sure that Auto-Resolve is disabled.

Get Response

  • Click Run

The request is sent, and we get a response back:

Parameters

Note: The API key changes, so you may need to visit the Flickr REST demo site and get an up to date API key.

The Schema tab changes to indicate that schema conflicts have occurred:

Conflicts

This means that the analysis of the response has indicated that there are conflicts between the current response and the previously inferred schema. In this case, this is as it should be, as no prior schema exists.

  • Open the Schema inspector

Conflicts

We can now resolve the conflicts manually.

  • Click Resolve Conflicts

For each detected conflict, we will get a notification and can take action as needed.

conflict

In this case, we can assume all conflicts should be resolved (again, no previous schema).

  • Click Yes To All*

All conflicts are then automatically resolved, and logged in the Schema log:

conflicts

Inferred Schema

When all conflicts have been resolved, the schema is added in the Schemas tab:

conflicts

So far we can see one namespace, and the associated XSD schema for it. As this schema is based on only one response we can refine it by making some more requests. While doing so we should try to vary the responses so that they are as different as possible. For instance, we can issue an invalid request so that we can infer the schema for a fault, or make a request for a query that returns an empty result set, and so on.

Adding Definitions

More responses can be added to the Schema automatically, by simply sending a different request. Since we can assume that the responses will be valid, we can use the “Auto-Resolve” feature.

  • Go back to the Conflicts tab

Parameters

  • Make sure that Auto-Resolve is enabled.

A Different Request

To get a different response, we need to change the request:

Parameters

  • Remove the api_key value

This will ensure that we get an error response.

  • Click Run

The request is sent, and we get a response back:

Parameters

This time, as conflicts occur they are resolved and logged automatically:

conflicts

Updated Schema

When all conflicts have been resolved, the new response is included in the schema in the Schemas tab:

conflicts

The new response has been included in the schema:

Before After
Before Before

You can now keep modifying requests and build up your schema.

Help and Feedback

You did not find what you looked for?

© 2016 SmartBear Software


×
Didn't find an answer? Try searching here: