ICF Service based&nbsp…

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' .   (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 .
                ENDIF .

            WHEN  'GET' .    (Read)
                CALL  METHOD get_data
                    EXPORTING
                        server  server
                    IMPORTING
                        e_data  ls_response .

            WHEN  'PUT' .    (Update)

        ENDCASE .

   CALL METHOD SERVER->RESPONSE->SET_CDATA( DATA L_VERB ).
        CREATE OBJECT  lo_json_serializer
            EXPORTING
                data ls_response . Data to be serialized

Serialize ABAP data to JSON
        CALL  METHOD lo_json_serializer ->serialize .

Get JSON string
        CALL  METHOD lo_json_serializer ->get_data
            RECEIVING
                rval  l_json .

Sets the content type of the response
        CALL  METHOD server ->response ->set_header_field (
                name    'Content-Type'
                value  'application/json; charset=iso-8859-1'  ) .

        CALL  METHOD server ->response ->set_cdata (  data l_json  ) .

    ENDMETHOD .

保存,激活

然后测试
我用的postman
下载和使用参考:http://jingyan.baidu.com/article/eb9f7b6d861da9869364e83a .html


简单点儿就是在sicf里测试,然后把网址复制过去就行了
get
ICF <wbr>Service <wbr>based <wbr>on <wbr>REST <wbr>and <wbr>JSON <wbr>simple <wbr>demo
post
打外部断点看下:
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值