The SAP ABAP stack can also interface using REST protocol. To support this interface protocol SAP has developed special classes in the ABAP stack.
Questions that will be answered in this blog are:
- How do I create a REST interface in ABAP stack?
- How do I test a REST interface in ABAP stack?
- Which tools to use to developer REST interface?
REST in ABAP
SAP delivers in the ABAP netweaver stack the ABAP REST library. The full specification can be found on the SAP help portal. The help portal also contains a small tutorial. Next to the pre-delivered REST library classes there are no tools for you available to faster develop REST in ABAP. It is coming down to SE24 and SE80.
Good reference blog is the SAP blog on usage of REST in Netweaver 7.4. This also explains the generic REST architecture implementation in ABAP.
Creating REST service in ABAP
We will create a simple Hello World REST service in ABAP. There are 2 main classes in REST ABAP: the application class handling the URL and the resource class where the logic is.
Start transaction SE24 and create a new class inheriting from the SAP delivered class CL_REST_HTTP_HANDLER:
important here to press the inheritance button! Fill out CL_REST_HTTP_HANDLER as superclass:
It is mandatory to redefine the GET_ROOT_HANDLER method:
For now just leave the method empty. Save and generate.
Now create the REST resource class based on inheritance of CL_REST_RESOURCE:
Now redefine the GET method:
No we add a simple implementation by simply adding the text ‘Hello World’:
Save and activate this class.
Now we go back to the previous class: the application class. In here we now edit the GET_ROOT_HANDLER implementation we left empty earlier:
If the URL is getting the input /hello then the handler class (our resource class) ZCL_HELLO_WORLD_RES_REST is called. This class will return the string.
Save and activate again. The coding work is done.
Runtime implementation
Now we need to make a runtime implementation. Goto transaction SICF and select the main node default_host first. Then select from the menu Service/Host the option Create Service:
Fill out the name of the service and click ok. In the next screen give a description and in the Handler List section refer to the application class ZCL_HELLO_WORLD_REST:
Save the service. The service is created but not active. To activate right click on the service and select Activate:
Testing the service
From the previous SICF screen right click the service again and select the option Test Service. A screen will come that says “No suitable resource found”. Now modify the URL by adding /hello after the test in the URL, and press enter again:
The URL build up: the test is the name defined in SICF. The /hello was defined in the application class.
Authorizations and security
The REST library has no specifics about authorization and security. So you have to take care your self.
Business authorization security: has to be built in via AUTHORITY-CHECK statements at the correct spots.
Technical security is provided in the Logon Data tab on the SICF node. Here you can set requirements for the technical logon method and if you only allow https.
REST versus ODATA
ODATA is based on REST and has more features. If you have a choice, you best use ODATA. ODATA exposing is described in this blog.
In SAP REST is supported, but you have to code a lot, and limited tools are available. For ODATA much more development and monitoring tools are available.
Urgent:
Class [cl_rest_http_handler / cl_rest_resource] does not exist. I’m following your steps but this error is coming. How to fix this ?
Hi Sridhara,
CL_REST_HTTP_HANDLER does exist in higher netweaver versions. If you are running old system, the class might not yet exist.
What his the basis version you are using?
Regards, Frank
SAP ECC 6.0
What is the alternate solution for those 2 super classes ?
There is no alternative. If your netweaver base version is not high enough, it will not properly support REST protocol.
ECC 6.0 is the functional version. What is the basic netweaver version? EHP version?
EHP5
The REST library is available as of Netweaver 7.4
https://help.sap.com/doc/saphelp_nw74/7.4.16/en-us/28/50217946b54e718e1f4afb35c4c283/frameset.htm
Most EHP5 are installed on 7.3.
HI,
How to find the BAPI url & How to test the BAPI in postman ?
I have created a BAPI in SAP application with the following steps.
1. created 2 structure ( import / export )
2. created function module
3. created the business object and finally I have inserted the function module into this business object.
4. and I have change the status of BO (business object) to implemented and released.
How to do this ?
See for example this blog: https://blogs.sap.com/2019/10/23/central-user-administrationcua-configuration/ (section 9)
or check the CUA Cookbook section Setting Up “Field Distribution Parameters”