Show TOC

Using Absolute URIsLocate this document in the navigation structure

Procedure

If the URI in a request is an absolute URI, for example http://myserver:4711/sap/bc/rest_cars/Cars/1 instead of /Cars/1 in a request part, then you must specify the base URI of the REST service to make the routing work on creating the HTTP request provider CL_REST_HTTP_REQ_PROV.

Example: This multipart request is identical to the previous Example, except that the request URIs are specified absolutely.

            --34fe-f07f-960e
Content-Type: application/http

GET http://myserver:4711/sap/bc/rest_cars/Cars/1 HTTP/1.1


--34fe-f07f-960e
Content-Type: application/http

PUT http://myserver:4711/sap/bc/rest_cars/Cars/1 HTTP/1.1
Content-Type: application/xml
Content-Length: 1000

<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<CAR>
<MODEL_NAME>Golf 7 Plus</MODEL_NAME>
<MANU_ID>1</MANU_ID>
<PRICE>20399.99</PRICE>
<CURRENCY>EUR</CURRENCY>
<MODEL_YEAR>2012</MODEL_YEAR>
</CAR>
</asx:values>
</asx:abap>

--34fe-f07f-960e
Content-Type: application/http

GET http://myserver:4711/sap/bc/rest_cars/Cars/1 HTTP/1.1


--34fe-f07f-960e--

         

The routing request cannot work using the processing as given in section Processing Entities because the path information does not match the attached URI templates in the REST application. To make it work, specify the called ICF URI ( script name) when constructing the HTTP request provider CL_REST_HTTP_REQ_PROV.

In this case the coding looks as follows (identical parts to the code example before were omitted):

            method if_rest_resource~post.
  data:
        ...
        lv_script_name type string.

  lv_script_name = io_entity->get_header_field( if_http_header_fields_sap=>script_name ).

  lt_entities = lo_mp_entity_req->get_entities( ).
  loop at lt_entities assigning <lo_entity>.
    create object lo_req_prov
      exporting
        iv_script_name = lv_script_name
        io_entity      = <lo_entity>.
...
  endloop.
...
endmethod.