Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
rajat_verma3
Explorer
92,459
A REST API is Representational State Transfer Application Programming Interface that conforms to the constraints of REST architectural style and allows for interaction with RESTful services.

The most common methods are: GET, POST, PUT, and DELETE,

These methods would be used, a GET request to retrieve a record, a POST request to create one, a PUT request to update a record, and a DELETE request to delete one


Scenario -->  Need to provide Driver detail based on the Driver ID.

Step 1 -->

Driver data base table.


 

Step 2 -->

Create Request Handler class ‘ZCL_DRIVER_REQ_HANDLER’ and inherit with standard class ‘CL_RESTHTTP_HANDLER’



Note --> It is mandatory to implement GET_ROOT_HANDLER method otherwise it will give syntax error.


Step 3 --> 

Create Request Provider class ‘ZCL_DRIVER_REQ_PROVIDER’ and inherit with standard class ‘CL_REST_RESOURCE’



Step 4 -->  Now Implement IF_REST_RESOURCE~GET method for reading the data.

After reading the data call /UI2/CL_JSON=>SERIALIZE() method to convert ABAP structure into JSON format.


Step 5 --> Implement GET_ROOT_HANDLER method of Request Handler class.

Here we need to link Request Handler class and Request Provider class with help of router.


Step 6 -->  Create Service Element, TCode SICF



Step 7 -->   Link Handler list, here we need to define our Request Handler class ‘ZCL_DRIVER_REQ_HANDLER’.


 

Step 8 --> Activate Service.




Step 9 --> Test Service.



 

Result --> Here we are passing Driver ID = 002 and based on ID data is displayed in JSON format.


Post Method call --> 

Scenario --> We need to create new Driver detail in the data base. As you can see Driver ID ‘002’ is only exist in the system and now new ID ‘001’ should be created.


 


 

In variable LV_DATA, data is coming in JSON string


Call /UI2/CL_JSON=>DESERIALIZE() method to convert JSON string into ABAP structure.


Here is the new entry with ID ‘001’


 

Conclusion --> 


After reading this blog you will be able to create simple Rest API and you will also have a idea of reading parameters in Request Provider class.

Please feel free to suggest if any correction is needed:)
12 Comments
former_member804381
Discoverer
0 Kudos
Hi Rajat

Trying to implement something similar, your step 4 and step 5 is little confusing. Could you ellaborate how you implemented standard interface methods GET with custom logic showing in screen shot to read driver details from table ?

many thanks

Drashti
former_member804381
Discoverer
solved myself.

Nice blog Rajat and very useful when Gateway is not an option.
Clark_Huang
Product and Topic Expert
Product and Topic Expert
0 Kudos
HI Rajat,

Do you know how to handle the authetication of this restful api?

I tested the api successfully in "Test Service". But face the 401 issue when call this api in postman.
former_member827353
Discoverer
Hi Rajat,

it's very nice blog.
david_fryda2
Participant
0 Kudos
Hi Rakst,

Thank you.

What not simply use oData?

 

Regards.

 
plato
Discoverer
0 Kudos
Is it possible to create multiple endpoints with handler?
xiswanto
Active Participant
Hello Clark,

 

not sure if you've solved this yet.

To solve 401 issue, you must go to 'Authorization' tab ( which is beside 'Params' tab, choose the authentication type ( most commonly used is 'Basic Auth' ), provide the username and password which exist in the SAP system client you are testing at.
xiswanto
Active Participant
Very informative blog.

Good ways to accept incoming REST API content aside from Odata services.
wispmacshah
Explorer
0 Kudos
You can define different endpoints in your root handler method using the router - attach method. You can either attach different provider class or handle the processing within a single provider class as you need.
0 Kudos
Thanks for sharing.

From an operational support perspective. What are the options available to monitor the calls at the SAP end?

For example in the case of proxy web services SAP has a utility tool like SXMB_MONI is there something similar available for the cases implemented by the above procedure?

 

Regards,

Abhinav
DaddyBear
Discoverer

After more than a hundred visited blogs and vlog, this might be the BEST article I ever read to learn more about API REST development.

Big bonus : we finally got rid of OData !

One small suggestion : you can also use the superclass CL_RESTHTTP_HANDLER referring class to redefine method HANDLE_CSRF_TOKEN so you gain more liberty and control on it.

One small request : any sugestion on how to dynamically assign template and DPC class in redefined method GET_ROOT_HANDLER ?

However: sincere thanks and congratulations for this article. It made my day.

 

SANKET20
Explorer
0 Kudos

how we can call post method from postman with input.

 

Labels in this area