0% found this document useful (0 votes)
116 views25 pages

REST API in SAP ABAP 1742729124

The document provides a comprehensive guide on implementing REST APIs in SAP using ABAP, detailing the creation and implementation of Resource Provider and Request Handler classes. It covers standard HTTP methods (GET, POST, PUT, DELETE), service definition, testing procedures, and usage of tools like Postman for testing API requests. The document also emphasizes the importance of CSRF token validation during POST requests.

Uploaded by

Veeru Thunga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views25 pages

REST API in SAP ABAP 1742729124

The document provides a comprehensive guide on implementing REST APIs in SAP using ABAP, detailing the creation and implementation of Resource Provider and Request Handler classes. It covers standard HTTP methods (GET, POST, PUT, DELETE), service definition, testing procedures, and usage of tools like Postman for testing API requests. The document also emphasizes the importance of CSRF token validation during POST requests.

Uploaded by

Veeru Thunga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

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

Email: ypkrbandi@gmail.com 1|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

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

Resource Provider Class


Create Resource Provider Class
Create a Resource Provider Class and add class CL_REST_RESOURCE as a super class

Email: ypkrbandi@gmail.com 2|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Class - CL_REST_RESOURCE and its methods

Email: ypkrbandi@gmail.com 3|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Implement Resource Provider Class


GET Method
Redefine the Get Method to get the resource details

Get method has no parameters.

Email: ypkrbandi@gmail.com 4|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Use MO_REQUEST to get the requested URI details


Use MO_RESPONSE to send the resource details

Methods of the Interface IF_REST_REQUEST

Methods of the Interface IF_REST_RESPONSE

Email: ypkrbandi@gmail.com 5|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Implementation for the GET method to get the resource details

Email: ypkrbandi@gmail.com 6|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

POST Method
Implementation for POST method to create resource, POST method has no parameters.
Use MO_REQUEST to get the request details.

Email: ypkrbandi@gmail.com 7|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

PUT Method
Redefine the Put method to update the Student details

Put method has one parameter

Implement the Put method to update the student table data

Email: ypkrbandi@gmail.com 8|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

DELETE Method
Redefine the Delete method to delete the table record

Delete method has no parameters

Email: ypkrbandi@gmail.com 9|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Implement the Delete method to delete the record

Request Handler Class


Create Request Handler Class
Create a Request Handler Class and add the class CL_REST_HTTP_HANDLER as a super class

Email: ypkrbandi@gmail.com 10 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Class - CL_REST_HTTP_HANDLER and its methods

Implement Request Handler Class


Method GET_ROOT_HANDLER redefinition is mandatory

Email: ypkrbandi@gmail.com 11 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Redefine the GET_ROOT_HANDLER Method

Method GET_ROOT_HANDLER has one parameter

Implement the GET_ROOT_HANDLER to call the Resource Provider class.

Email: ypkrbandi@gmail.com 12 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Define and Test the Services


Create the service
Tcode – SICF to create the service and add the Request Handler class as a Handler

Click on the Host/Service by selecting the default_host

Email: ypkrbandi@gmail.com 13 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Provide the service name

Add the Handler class

Email: ypkrbandi@gmail.com 14 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Activate the Service

Test the Service


Right click on the required service and click on the Test service

Email: ypkrbandi@gmail.com 15 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Here, error will be shown without passing Resources Name

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

REST API in SAP

Testing using Postman Tool


Get Request
Student details are fetched using GET request

Post Request
Table date before posting

CSRF Token validation is required while posting.

Email: ypkrbandi@gmail.com 17 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Get the CSRF Token using GET request by adding key as x-csrf-token and value as fetch to request
headers

Copy CSRF token from the response header of GET response

Add the CSRF token to the Post request header

Request body

Email: ypkrbandi@gmail.com 18 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Post executed successful.

Data is inserted into table

PUT Request
Add the CSRF token to the request header

Add the request body

Email: ypkrbandi@gmail.com 19 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Student table data is updated

DELETE Request
Send the Delete request

Response of delete request

Requested Record has been deleted in the student table

Email: ypkrbandi@gmail.com 20 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Consume GET and POST REST API


Consume GET request
Implementation to get the REST API Resource details

Email: ypkrbandi@gmail.com 21 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Email: ypkrbandi@gmail.com 22 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Consume POST request


Implementation to create the REST API Resource details

Email: ypkrbandi@gmail.com 23 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Email: ypkrbandi@gmail.com 24 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

REST API in SAP

Email: ypkrbandi@gmail.com 25 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy