cancel
Showing results for 
Search instead for 
Did you mean: 

How to use REST services in Webdynpro abap (WDA)?

Former Member
0 Kudos

Hi,

can any one tell me how to use REST servieces in webdynpro abap if possible with example .

Thanks Regards,

Naga Punnarao.

Accepted Solutions (0)

Answers (2)

Answers (2)

amy_king
Active Contributor
0 Kudos

Hi Naga,

REST web services are callable over HTTP so you would use a CL_HTTP_CLIENT object to handle the call to the web service. There is nothing specific to Web Dynpro in the code; you could write this code in any class method, function module, subroutine, etc. For example...

DATA client TYPE REF TO if_http_client.

CALL METHOD cl_http_client=>create_by_url
     EXPORTING
         url              = '
https://host:port/WebService/operation'
     IMPORTING
         client         = client
     EXCEPTIONS
         OTHERS  = 4.

* Set request method to GET or POST
   client->request->set_method( if_http_request=>co_request_method_post ).

* Set the request form data

   client->request->set_form_field(
       name  = 'FORM_FIELD_ONE'
       value   = value_one
   ).

   client->request->set_form_field(
       name  = 'FORM_FIELD_TWO'
       value   = value_two
   ).


* Send HTTP request
   CALL METHOD client->send
       EXCEPTIONS
          OTHERS    = 5.

   CASE sy-subrc.
         WHEN 0.  " send OK
*           Receive HTTP response
             CALL METHOD client->receive
                 EXCEPTIONS
                     OTHERS    = 4.

             CASE sy-subrc.
                 WHEN 0.  " receive OK
*                  Examine messages returned from the web service call
                     lv_cdata = client->response->get_cdata( ).

                 WHEN OTHERS. " receive error
                     CALL METHOD client->get_last_error
                         IMPORTING
                             code        = ls_http_error-code
                             message = ls_http_error-message.
              ENDCASE.

       WHEN OTHERS. " send error
           CALL METHOD client->get_last_error
               IMPORTING
                   code        = ls_http_error-code
                   message = ls_http_error-message.


      ENDCASE.

You can use class CL_IXML to parse the CDATA returned by the web service. If you need to pass binary data to the web service, for example file contents, the approach is a little different.

Cheers,

Amy

former_member184155
Participant
0 Kudos