Skip to Content
Author's profile photo Amaresh Pani

Calling an external RESTful service from ABAP – HTTP Method GET

HTTP POST  method:–http-method-post

I have made inline code explanation. Please go through step by step description.

Scenario: GET operation to access:

1) Create a RFC destination of type (HTTP Connections to External Server)


content-type: application/json

DATA: lo_http_client     TYPE REF TO if_http_client,
         lo_rest_client     TYPE REF TO cl_rest_http_client,
         lv_url             TYPE        string,
         lv_body            TYPE        string,
         token              TYPE        string,
         agreements         TYPE        string,
         "Create a structure(or deep) that exactly matches your JSON response
         abap_response      TYPE        zca_serno_ln,
         lo_response    TYPE REF TO     if_rest_entity.
* Create HTTP intance using RFC restination created
* You can directly use the REST service URL as well
      destination              = 'VENDAVO'    " Logical destination (specified in function call)
      client                   = lo_http_client    " HTTP Client Abstraction
      argument_not_found       = 1
      destination_not_found    = 2
      destination_no_authority = 3
      plugin_not_active        = 4
      internal_error           = 5
      OTHERS                   = 6
* If you are using cl_http_client=>create_by_url use this code to supress and pass your
 * HTTP basic authenication 
 *  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
 *  DATA l_username TYPE string.
 *  DATA l_password TYPE string.
 *  l_username = 'user'.
 *  l_password = 'password'.
 *  CALL METHOD lo_http_client->authenticate
 *      username = l_username
 *      password = l_password.
* Create REST client instance
   CREATE OBJECT lo_rest_client
       io_http_client = lo_http_client.
* Set HTTP version
   lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_0 ).
   IF lo_http_client IS BOUND AND lo_rest_client IS BOUND.
     DATA(id) = 'XYZ'.
     CONCATENATE 'agreements/' id INTO lv_url.
* Set the URI if any
         request = lo_http_client->request    " HTTP Framework (iHTTP) HTTP Request
         uri     = lv_url                     " URI String (in the Form of /path?query-string)
* Set request header if any
     CALL METHOD lo_rest_client->if_rest_client~set_request_header
         iv_name  = 'auth-token'
         iv_value = token.
     lo_rest_client->if_rest_client~get( ).
* HTTP response   
     lo_response = lo_rest_client->if_rest_client~get_response_entity( ).
* HTTP return status   
     DATA(http_status)   = lo_response->get_header_field( '~status_code' ).
* HTTP JSON return string   
     DATA(json_response) = lo_response->get_string_data( ).
* Class to convert the JSON to an ABAP sttructure
    DATA lr_json_deserializer TYPE REF TO cl_trex_json_deserializer.
    CREATE OBJECT lr_json_deserializer.
    lr_json_deserializer->deserialize( EXPORTING json = json_response IMPORTING abap = abap_response ).

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Sunil Khemchand
      Sunil Khemchand

      Hi Amaresh,

      I have similar requirement, ie., calling an external restful service running on an external amazon instance, and I am trying to following the steps you have described above. But, I am having an issue with RFC destination. No matter what target host I provide, either valid or invalid, the "Connection Test" always returns success( http status 200 OK), but the method GET always returns an error.

      Have you encountered this before? Is there any other way to test if the RFC destination i have defined in SM59 is the correct one?

      Appreciate your earliest reply.



      Author's profile photo Amaresh Pani
      Amaresh Pani
      Blog Post Author

      Hi Sunil - Are you able access the service from your browser? Also

      Have you tried the other option by providing the REST URL directly as I have explained above (as below) instead of going SM59 route?

      1. * If you are using cl_http_client=>create_by_url use this code to supress and pass your  
      2. * HTTP basic authenication   
      3. *  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled. 
      4. *  DATA l_username TYPE string. 
      5. *  DATA l_password TYPE string. 
      6. *  l_username = 'user'. 
      7. *  l_password = 'password'. 
      8. *  CALL METHOD lo_http_client->authenticate 
      9. *    EXPORTING 
      10. *      username = l_username 
      11. *      password = l_password. 
      Author's profile photo Former Member
      Former Member

      Hi Amaresh,

      I am using Solman system where the class ( cl_rest_http_client ) mentioned in your post does not exist in my system probably due to lower level patch.

      My requirement is similar to this post, is there any other alternative class or others ways available to achieve this.

      Author's profile photo Juan Lee
      Juan Lee


      I have ws that return 2 sets of data: a simple result string and tables of entries as shown here.

      is there a way to retrive the data based on the JSON string 'RESULT' or 'OUTTAB'?

      I would to just capture RESULT to check message is sucessful -> import table into lr_json_deserializer.


      Author's profile photo Former Member
      Former Member

      Thanks, Amaresh, really useful!

      Is there any way to trace the outgoing generated HTTP request and watch its content?


      Author's profile photo Amaresh Pani
      Amaresh Pani
      Blog Post Author

      Hi Agu - You need trace them at ICM level.


      Amaresh Pani


      Author's profile photo SAP Seeker
      SAP Seeker

      Nice blog Amaresh.

      I tried to implement something similar but unable to get data. Also, without passing the password, is there any option to authenticate ? In your blog, can you explain where did you get the token from ?


      Author's profile photo Orhan Turgut Keskinel
      Orhan Turgut Keskinel


      I need to send three form-data parameters (username-password-email) to the web service. How can I send these parameters? I have to use get method like in this solution.

      Kind regards,

      Author's profile photo Ivan Ivanov
      Ivan Ivanov

      Hi all,


      I bumped into a situation where with a GET method my client app receives chunked data ending in a form :

      The answer seems valid as per the RFC describing HTTP 1.1.
      Any idea of how to handle this response without needing to write my own navigation class?


      Author's profile photo Neha Chandel
      Neha Chandel

      Hi Amaresh,


      I'm getting status code - 404  on receive method

      Author's profile photo Muhammad Ilyas
      Muhammad Ilyas

      The code is implemented but found it returns only 1 entity. 🙁

      Confused what is wrong, I took to SMICM log too. I took the URL to Postman but found 5 records for $top=5 keyword but ABAP returns only 1.