REST API in SAP ABAP 1742729124
REST API in SAP ABAP 1742729124
Contents
REST API ........................................................................................................................................................ 2
Resource Provider Class ................................................................................................................................ 2
Create Resource Provider Class ................................................................................................................ 2
Implement Resource Provider Class ......................................................................................................... 4
GET Method .......................................................................................................................................... 4
POST Method ........................................................................................................................................ 7
PUT Method .......................................................................................................................................... 8
DELETE Method..................................................................................................................................... 9
Request Handler Class ................................................................................................................................ 10
Create Request Handler Class ................................................................................................................. 10
Implement Request Handler Class .......................................................................................................... 11
Define and Test the Services ....................................................................................................................... 13
Create the service ................................................................................................................................... 13
Test the Service ....................................................................................................................................... 15
Testing using Postman Tool ........................................................................................................................ 17
Get Request ............................................................................................................................................ 17
Post Request ........................................................................................................................................... 17
PUT Request ............................................................................................................................................ 19
DELETE Request ...................................................................................................................................... 20
Consume GET and POST REST API............................................................................................................... 21
Consume GET request............................................................................................................................. 21
Consume POST request........................................................................................................................... 23
REST API
REST API is a Representational State Transfer Application Programming Interface
REST API is consumed using HTTP protocol
Its standard methods are GET, POST, PUT, and Delete.
Get request is used to get the details from the resource
Post request is used to create the resource.
Put request is used to update the existing resource.
Delete is used to delete the resource.
ABAP provides tools to create and consume RESTful APIs to integrate with other systems.
CL_REST_RESOURCE as standard class and it contains HTTP methods.
CL_REST_HTTP_HANDLER a standard class used to handle the Request
POST Method
Implementation for POST method to create resource, POST method has no parameters.
Use MO_REQUEST to get the request details.
PUT Method
Redefine the Put method to update the Student details
DELETE Method
Redefine the Delete method to delete the table record
Email: ypkrbandi@gmail.com 10 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 11 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 12 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 13 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 14 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 15 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Send the request with adding the resource name to the URI
Tcode- /iwfnd/gw_client, send the Get request from the gateway client
Email: ypkrbandi@gmail.com 16 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Post Request
Table date before posting
Email: ypkrbandi@gmail.com 17 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Get the CSRF Token using GET request by adding key as x-csrf-token and value as fetch to request
headers
Request body
Email: ypkrbandi@gmail.com 18 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
PUT Request
Add the CSRF token to the request header
Email: ypkrbandi@gmail.com 19 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
DELETE Request
Send the Delete request
Email: ypkrbandi@gmail.com 20 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 21 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 22 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 23 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 24 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy
Email: ypkrbandi@gmail.com 25 | P a g e