Building RESTful webservices for ABAP still seems to be an issue for SAP Netweaver. In fact, it isn’t. The great article “
” shows how to implement basic RESTful functionality in ABAP. Let’s take this concept further.
All development objects mentioned in this tutorial are available as SAPLink nugget. To avoid inconsistencies while activating, please first activate ZIF_RESOURCE_CONTROLLER and ZRESOURCE_ROUTNG in order to activate any other development objects shipped with this nugget.If you haven’t heard about REST before, you should read this
in order to get familiar with the REST paradigm. Please note, the sources for this example are available as a
What do we miss?
A good introduction to the REST paradigms is explained in the article. There are some restrictions with this approach. I would like to explain to you, what restrictions are existent and how to bypass them. First of all: For RESTful webservices, a hierarchy of resources would be needed. This means, in terms of the SAP flight model shipped with all WebAS ABAP releases, there should be flight connections (sub-resources) available for certain carriers (super-resources). For example, when performing “GET” requests using a standard browser…
http://<yourServer>/resources/scarr/LH/ returns details of the carrier Lufthansa…0.1.
http://<yourServer>/resources/scarr/LH/SPFLI/* returns all flight connections related to Lufthansa…0.1.
http://<yourServer>/resources/scarr/LH/SPFLI/402 returns the specific flight connection “402” related to Lufthansa. Second, there should be some kind of delegation logic for our endpoint handler class which is dealing with all requests sent to a specific endpoint. This means, we only want to use one single ICF handler which should be responsible for delegating the requests to another resource handler class according to some routing logic. Parameters passed in the URL, like “LH” and “402” serve as “input parameters” for the methods invoked from this class. The parameters should be handed over in a structured way.
First, we need to create an endpoint handler for an URL on the Application server.
Call transaction SICF and press F8.
In the tree bar, right click on the “sap” node and choose “New Sub-Element”
!https://weblogs.sdn.sap.com/weblogs/images/251763241/RA_002.png|height=400|alt=Create new independent Service|width=500|src=https://weblogs.sdn.sap.com/weblogs/images/251763241/RA_002.png|border=0!
Choose a name for the new independent service. In the example, this endpoint is called “resources”.
In the maintenance screen, go to tab “Handler List”. Type in the class name of the class which is handling requests sent to this node. In our case, there is already a class which is named ZCL_RESTFUL_CONTROLLER shipped with the nugget file. This class is implementing the Interface IF_HTTP_EXTENSION, since this is needed to register a handler class for a node represented by an URI.
(Please note, the sources for this example are available as a