You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

This page describes the steps for calling a web service using the REST protocol. This page also gives you background information on how web services work within the Blueriq architecture. The following steps are required:

Importing

In order to interpret an XML response from a REST web service, Blueriq needs to import an XSD. In contrast to SOAP, there may not be an explicit contract available for REST. You can use the API of the REST service to get XSD files.

If the REST service only gives example answers, you can generate an XSD file from the examples (see for instance http://www.freeformatter.com/xsd-generator.html).

Go to File → Import → Import XSD and provide the location of the XSD file. If you have multiple files (for example: your XSD is importing/including an XSD schema), provide a zip file with all needed files. This is essentially the same as importing a WSDL (Chapter 4 - Calling a SOAP service). Select the project for the import and you can choose whether to create a new module, or overwrite an existing one. The option 'Generate Domain' will automatically generate a domain model for you, based on the XSD schema. When this button is checked, entities, attributes and relations are created based on the type definitions in the XSD. When using an existing module, there may already be a domain model present, that uses identical names as in the XSD. When overwriting, conflicting elements are not created. Obviously, these problems do not occur if you use a new module. When 'Generate Domain' is unchecked, no domain model is generated for you. In that case, you can later match the elements from the XSD to you own domain (explained later). In general, it is advised to use a separate module in order not to mix the domain model for the web service with the domain of your business.

You should get the message that the import was successful.

Mapping with Domain Model

Open your project and go the module which contains the web service. The module now has a Schema Set. This item can be found in the bar on the left side of the screen, as can be seen below.

The Schema Set defines which entities, attributes and relations are used by the web service (they map the XSD to the domain model). This works exactly the same for REST and SOAP, and the description can be found here: Chapter 4 - Calling a SOAP service.

Defining the REST service

In contrast to importing a WSDL, no service definition is automatically generated. You have to define how the REST service is called manually. Create a new REST service object and give your REST service a name.

Next, you need to specify the location of the REST service. This is an URL. You can already specify fragments and arguments here, but then you cannot change them later. For example, check http://services.faa.gov/airport/status/IAD?format=xml. In this case, airport, status and IAD are dynamic fragments and can change, depending on input by the user. You would only use http://services.faa.gov/ as location in this case.

Now specify the Schema Set that you want to use. Choose the Schema Set that you have imported earlier.

You can specify as many operations as you need, by pressing on the plus icon. Give every operation a unique name.

Request

If you want to dynamically change the address or send custom headers or body in your message, you need to specify a singleton entity from where the information is gathered (1). (2) shows the URL you are going to call. Items within {} are dynamic and determined at runtime. You can add static fragments (3) which are always the same, or dynamic fragments (4) which are filled by attributes of the request entity. You can specify arguments (5) of your request the same way. There are 4 different HTTP methods: GET, POST, PUT and DELETE. Most likely, the web service works with the GET method. This method does not alter the state of the web service and just asks for information. At (6) you specify what method to use.

You can also send a message to the REST web service as part of the HTTP headers. This happens more often with POST and PUT methods. This procedure is the same as for the response of the message that you find just below here.

Response

Now you can specify how your response message looks like. (1) lets you specify what kind of message it is (GET, POST, PUT or DELETE). If you need to set headers, then you can do so at (2) in the same way you set arguments or fragments earlier. If you need to send information in the body of the message, for example with a POST message, then you can specify this now. This is done in XML, and your Schema needs to be able to handle this. If you have a SimpleType in the schema, then you fill in an attribute at (5). If it is a complexType, then first choose which entity will be sent at (3) and then your attribute field (5) will switch to a relation field. Fill in the name of the relation between your singleton request entity and your data entity. Custom Schema Elements (4) are ways to fill in your schema in a different way other than with data from your profile. It is not needed at the moment (An example is a justification tree)

Bovenstaande tekst klopt niet met het plaatje hieronder. Daarnaast is onduidelijk wat bedoeld wordt met de laatste 2 zinnen.

 

Creating a Service Call

In order to call a REST web service, you create a service call of type AQ_WebServiceClient the same way as for SOAP web services (Chapter 4 - Calling a SOAP service). The only difference is that you select REST at the service dropdown. You usually do not want to supply a URL, as it will overwrite the dynamic URL generation of the REST service definition.

Using the Webservice

This is similar to SOAP (Chapter 4 - Calling a SOAP service).

  • No labels