Defining a custom REST service

  • 6 January 2021
  • 0 replies
  • 78 views

Badge +1

This help topic tells you how to define a REST service that is NOT predefined, that is, a REST service that you either generate yourself from SQL or that you program yourself as a custom REST service.

By default, non-predefined REST services are based on the "USoft REST Default Provider" functional type that USoft ships with the Service Definer product. Alternatively, you may want to use a different USoft default provider, or you may prefer to create a functional type of your own.

If you use the "USoft REST Default Provider" functional type, you can use the "Generate from SQL" utility to have a first working version of the target code generated by USoft. For an example of this, go to " Example: a REST service for retrieving data ".

Defining a REST service of a non-predefined type

To define a REST service of a non-predefined type:

1. Choose Define, REST Services from the menu.

2. Insert a new "REST Services" record and set its Service Name value to mycustomservice.

3. If you want to use the ready-made USoft-shipped default for non-predefined services, click the lookup button at the Functional Type field and select 'USoft REST Default Provider'.

Alternatively, if you want to use an existing Java class of your own, read the note at the end of this section.

4. Save work. Defaults are generated for Package and for Relative URI Path. Change these if appropriate.

5. Press the Check button on the right-hand side.

This causes the 'mycustomservice' REST Service to get the Correct = Yes setting.

To use an existing Java super class, base class or interface, declare that Java package by creating a record in table T_SVC_SUPER_CLASS. To do this, choose View, Objects from the menu, click on "SVC Super Classes" and fill out the form, taking USoft-shipped entries as an example. Enter a Functional Name as a unique handle for the code. Enter a Description and set Used for Class Type = REST Service. Save. You can now use the Functional Name when you select a functional type in Step 3.

Associating your REST service with a server

To associate your REST service with a server:

1. Choose Define, REST Services from the USoft Service Definer menu.

The "REST Services" window or tab appears.

2. Query the REST service that you want to expose.

3. When you have that REST service in view, click the Servers tab and specify the server where you want to publish the REST service, for example, the default server called 'Default'.

Get a list of available servers by pressing, in the Servers tab, the F12 key.

4. Save.

Associating the custom REST service with a connection

To associate the custom REST service with a connection:

1. In the "REST Services" window, for the REST service, click the Connections tab and specify the connection that you want the service to use.

To get a list of available connections by pressing, in the Connections tab, the F12 key.

2. Save.

(Re)publishing the custom REST service at the server

To (re)publish the custom REST service at the server:

1. Choose Define, Servers from the menu of the USoft Service Definer.

The Servers window or tab appears.

2. Query the server where you want to (re)publish the REST service.

3. Stop the Server if it was running. Do this by choosing Actions, Stop from the menu, or by clicking the Stop icon on the icon ribbon.

4. (Re)publish the service(s) associated with the server. Do this by choosing Publish, Publish Services from the menu, or by clicking the Publish Services icon on the icon ribbon.

5. Start the Server. Do this by choosing Actions, Start from the menu or by clicking the Start icon in the icon ribbon.

You can wrap Steps 3, 4 and 5 into one by choosing Publish, Publish and Restart from the menu or by clicking the "Publish and Restart" icon on the icon ribbon.

Setting up a test app in POSTMAN

Once you have a USoft REST service running, you can test its behaviour by using any favourite tool.

A good option is the free POSTMAN Client API tool which is available as a downloadable app or, with less features, via your web browser (registration required in each case). Go to :

https://www.postman.com/downloads/

Next step

You are now ready to define one or more methods for your custom REST service.

Defining custom REST methods

See also

Designing a custom REST service


This topic has been closed for comments