0
点赞
收藏
分享

微信扫一扫

ICF Service based on REST and JSON simple de


create class


​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



add interface IF_HTTP_EXTENSION


​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



Double click method


​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​


add test code:


​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



goto sicf


​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​


 add handler class

​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​
save, back and activated
​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​
test
​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​

​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​
Test passed.





next:





create a DB table  and table type



​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​

​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​





back to handler class



add two methods



​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​

Pay attention to the parameters
​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​​

​​​

ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo

​​



change handle_request method:






   METHOD if_http_extension ~handle_request .

* Objects
     DATA : lo_json_serializer  TYPE  REF  TO cl_trex_json_serializer .

* Variables
     DATA : l_verb       TYPE string .
     DATA : l_json       TYPE string .
     DATA : ls_response  TYPE zlm_rest1_tab .

* Retrieving the request method (POST, GET, PUT, DELETE)
    l_verb  = server ->request ->get_header_field ( name  =  '~request_method'  ) .

* Only methods GET, POST, PUT, DELETE are allowed
     IF  ( l_verb  NE  'GET'  )  AND  ( l_verb  NE  'POST'  )  AND
        ( l_verb  NE  'PUT'  )  AND  ( l_verb  NE  'DELETE'  ) .
       " For any other method the service should return the error code 405
       CALL  METHOD server ->response ->set_status (
           code    =  '405'
          reason  =  'Method not allowed'  ) .
       CALL  METHOD server ->response ->set_header_field (
          name   =  'Allow'
           value  =  'POST, GET, PUT, DELETE'  ) .
       EXIT .
     ENDIF .

     CASE l_verb .
       WHEN  'POST' .    " C (Create)
         "TODO: call method CREATE of the model
         CALL  METHOD post_data
           EXPORTING
            server  = server
           IMPORTING
            e_data  = ls_response
           EXCEPTIONS
            error   =  1
             OTHERS  =  2 .
         IF sy -subrc <>  0 .
    

举报

相关推荐

0 条评论