In the first part we had a look at 3 features:
- Swagger Documentation
- Support for Partial Responses
- Ignore Additional fields in Response
In this post we’ll look at three other features for REST support in BW.
Creating XML Schemas for use in REST Services
So BW’s data model being XML, everything will need a schema. If you use a Swagger document to generate a REST service (API first approach) or to invoke a REST service, the schemas are autogenerated for you. However, if you feel that you would like to manually generate a schema from Swagger, you can just right click on the schema and look at the available options to generate a schema.
However there are two other options BW provides to generate a schema. Let’s look at these in detail.
The first one is Generate a schema from JSON Payload . This option is available when you right click on the Schemas folder and Select New-> XML Schema for JSON Payload.
In the above example a schema called MyBooksResource.xsd is generated in the Schemas folder as shown below:
This is a very handy mechanism especially for invoking REST services when you don’t have a swagger specification.
The next wizard (which is relatively unknown) is the ability to create a JSON Schema from SQL. You can trigger this wizard by right clicking on a JDBC Connection and selecting BW JSON Utils -> Create schema from SQL
This will bring up Eclipse’s DTP SQL Query Builder which is a visual way to build SQL queries. You can add tables and views and build your query visually as well as test them out in the Query builder and then click Ok. The wizard will then ask you for an element name and generate a schema in the schema folder. This is really useful when trying to expose data in databases via REST services. You can quickly now create a rest service add a JDBC activity with the same query and use the Copy-Of mapping to expose your Data quickly and easily.
Exception Handling with Status Codes
A user can define custom status codes in the Response Status tab of the operation. The first column is to define the Status code e.g. 500, the second column for type e.g. String or XSD Element and the third would be the Reason Phrase e.g Internal Server Error.
Once a status code is defined, it can be easily used in the scope of the operation with a ‘Reply’ activity by choosing the new Fault that is created in the dropdown.
Once the 800 Fault is chosen the activity Input will show the custom schema as below