Changing the HTTP Method of a REST Virtual Service
When configuring the routing step of a REST virtual service, you specify whether to route the requests to the native service with the same HTTP method that is contained in the requests (GET, POST, PUT, DELETE), or whether to route the requests with a different HTTP method. This applies only to virtual services, not to connector virtual services.
Typically you want to pass each request to the native service with the same HTTP method that is contained in the request. For example, if a request contains a GET method, you allow the GET method to be passed to the native service. However, there might be rare cases in which you want to change the HTTP method of a request to a different HTTP method. For example, you might want to:
Expose an XML service as a REST service.
In this case, the service you create would be a Virtual XML service that exposes the HTTP methods GET, POST, PUT and DELETE, but the routing method would always be POST.
Expose a REST service whose virtual REST service only exposes the POST method
To change the HTTP method of a REST request, in the REST virtual service's Routing Rule step, set the value of the HTTP Method field either statically (by explicitly setting the value to GET, POST, PUT or DELETE) or dynamically (by setting the value to CUSTOM).
In order to use the
CUSTOM option to set the field dynamically, you must write a IS service that sets a value of GET, POST, PUT or DELETE for a predefined context variable named ROUTING_METHOD. You need to invoke this service in the virtual service's
In Sequence step. For details, see
Changing HTTP Methods in Requests
Dynamically Using a Context Variable.
Note:
Use this feature carefully, since changing HTTP methods to certain other HTTP methods could result in unintended results or errors. For example, changing an inbound GET request to a DELETE request would be a serious mistake if the deletion was not intended and the native REST service actually deleted a resource when invoked with a DELETE method. Additionally, an incoming POST or PUT request cannot be translated into a GET or DELETE if the request has nested elements. For more information, see
Implications of Changing HTTP
Methods.