
Figure 1
Figure 2
Figure 3
&---------------------------------------------------------------------*
*& Report Z_TEST_API
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_test_api.
DATA: lt_header_fields TYPE tihttpnvp,
mv_uri TYPE string,
mv_response TYPE string,
mo_http_client TYPE REF TO if_http_client,
mt_header_fields TYPE tihttpnvp.
DATA: lv_json TYPE /ui2/cl_json=>json,
ls_response TYPE Z******* "A structure of a custom type, the same as the result..
DATA lo_response TYPE REF TO if_rest_entity.
PARAMETERS: p_rfqid TYPE numc10. "Our Input Parameter
mv_uri = '/PromenaRFQ/1.0/quick-rfq/awarding-winners'. "The extension of our API that we will append to the end of our link."
CALL METHOD cl_http_client=>create_by_destination
EXPORTING
destination = 'Z_TEST_DESTINATION' " Logical destination (specified in function call)
IMPORTING
client = mo_http_client " HTTP Client Abstraction
EXCEPTIONS
argument_not_found = 1 " Connection Parameter (Destination) Not Available
destination_not_found = 2 " Destination not found
destination_no_authority = 3 " No Authorization to Use HTTP Destination
plugin_not_active = 4 " HTTP/HTTPS communication not available
internal_error = 5 " Internal error (e.g. name too long)
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
APPEND VALUE #( name = 'Content-Type' value = 'application/json' ) TO lt_header_fields.
APPEND VALUE #( name = 'accept' value = 'application/json' ) TO lt_header_fields.
mo_http_client->request->set_header_fields( fields = lt_header_fields ).
mo_http_client->request->set_method( if_http_request=>co_request_method_get ) .
v_json = /ui2/cl_json=>serialize( data = p_rfqid pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
mo_http_client->request->set_cdata(
EXPORTING
data = lv_json ).
CONCATENATE mv_uri '?quickRfqId=' p_rfqid INTO mv_uri.
cl_http_utility=>set_request_uri(
EXPORTING
request = mo_http_client->request " HTTP Framework (iHTTP) HTTP Request
uri = mv_uri " URI String (in the Form of /path?query-string)
).
mo_http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).
IF sy-subrc <> 0.
ENDIF.
mo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).
IF sy-subrc EQ 0.
mo_http_client->response->get_status( IMPORTING code = DATA(lv_code)
reason = DATA(lv_reason) ).
IF lv_code <> '200'.
CALL METHOD mo_http_client->close
EXCEPTIONS
http_invalid_state = 1
OTHERS = 2.
* MESSAGE lv_reason TYPE 'E'.
ENDIF.
ENDIF.
CLEAR mv_response.
DATA(lo_rest_client) = NEW cl_rest_http_client( io_http_client = mo_http_client ).
lo_response = lo_rest_client->if_rest_client~get_response_entity( ).
* Get string data
mv_response = lo_response->get_string_data( ).
/ui2/cl_json=>deserialize( EXPORTING json = mv_response CHANGING data = ls_response ).
Figure 4
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 |