0% found this document useful (0 votes)
38 views2 pages

API Test Sap

The document outlines an ABAP method for handling HTTP requests in a REST API context. It processes POST requests by deserializing JSON input, calling a function to retrieve data, and then serializing the response back to JSON format. The method also sets appropriate HTTP response status and content type based on the request method.

Uploaded by

Juzega Arana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

API Test Sap

The document outlines an ABAP method for handling HTTP requests in a REST API context. It processes POST requests by deserializing JSON input, calling a function to retrieve data, and then serializing the response back to JSON format. The method also sets appropriate HTTP response status and content type based on the request method.

Uploaded by

Juzega Arana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

DEVK916964 -> WB_SF_PRO0000000_IN_RPD_API_REST_JZEGARRA

-------------------------------------------------------------
METHOD if_http_extension~handle_request.
DATA: lwa_respuesta_rpd TYPE ztt_respuesta_rpd_4.

DATA:
lv_request_uri TYPE string,
lv_request_method TYPE string,
lv_content_type TYPE string,
lv_req_body TYPE string,
lv_lote TYPE string.

DATA: ltd_respuesta TYPE ztt_respuesta_rpd_4.

TYPES : BEGIN OF ty_in_data,


i_opc TYPE int2,
i_lote TYPE string,
i_iniprd TYPE int2,
END OF ty_in_data.

DATA:
_jsoninput TYPE ty_in_data,
respons_data_ TYPE string,
_response_ TYPE REF TO if_http_response.

DATA: lx_root TYPE REF TO cx_root.

lv_request_uri = server->request->get_header_field( name = '~request_uri' ).


lv_request_method = server->request->get_header_field( name =
'~request_method' ).
lv_content_type = server->request->get_header_field( name = 'content-
type' ).

lv_req_body = server->request->get_cdata( ).

CASE lv_request_method.
WHEN 'POST'.

IF lv_req_body IS NOT INITIAL.


REPLACE ALL OCCURRENCES OF REGEX '[^[:print:]]' IN lv_req_body WITH
space.
REPLACE ALL OCCURRENCES OF REGEX '#' IN lv_req_body WITH space.
CONDENSE lv_req_body.
* CREATE OBJECT cl_fdt_json.
TRY.

CALL METHOD /ui2/cl_json=>deserialize


EXPORTING
json = lv_req_body
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING
data = _jsoninput.

CALL FUNCTION 'ZBI_RPD_FNC003'


EXPORTING
i_opc = _jsoninput-i_opc
i_lote = _jsoninput-i_lote
i_iniprd = _jsoninput-i_iniprd
IMPORTING
e_respuesta_rpd = ltd_respuesta.

respons_data_ = /ui2/cl_json=>serialize(
data = ltd_respuesta
compress = abap_false
pretty_name = /ui2/cl_json=>pretty_mode-
camel_case ).

_response_ = server->response.
_response_->set_status( code = '200' reason = 'OK' ).
_response_->set_content_type( 'application/json' ).

IF sy-subrc EQ 0.
_response_->set_cdata( respons_data_ ).
ELSE.
_response_->set_cdata( respons_data_ ).
ENDIF.

CATCH cx_root INTO lx_root.


ENDTRY.
ENDIF.

WHEN 'GET'.

WHEN OTHERS.
ENDCASE.
ENDMETHOD.

You might also like