Using a provided Interface part for a 3rd-party REST service

In EGL, you can use the following Interface part to access a third-party REST service.

interface IRest
   function invokeGet(reqURL string in) returns(string)  
      {@getRest {uriTemplate="{reqURL}"}};
   function invokePost(reqURL string in, representation string in) returns(string)
      {@postRest {uriTemplate="{reqURL}"}};
   function invokePut(reqURL string in, representation string in) returns(string)
      {@putRest {uriTemplate="{reqURL}"}};
   function invokeDelete(reqURL string in, representation string in) returns(string) 
      {@deleteRest {uriTemplate="{reqURL}"}};
end

By using this Interface part as is, you do not have to write one. However, the work required to code the service-invocation statement is different.

Here is an example for asynchronous access, as occurs in Rich UI applications:
myVar IRest?;
myResource String = JSONLib.convertToJson(myRec);
call myVar.invokePost("http://www.example.com", myResource) 
    returning to myCallbackfunction;
Here is an example for synchronous access, as occurs elsewhere:
myString STRING:
myVar IRest?;
myResource String = JSONLib.convertToJson(myRec);
myString = myVar.invokePost("http://www.example.com", myResource);
The differences between synchronous and asynchronous access are as follows:
You might need a function prototype that has a different characteristic, such as a DELETE operation that does not require you to pass a representation. In that case, create a similar Interface part, but change the InvokeDelete function prototype or add a prototype with a different name. Here is a changed prototype:
function invokeDelete(reqURL string in) returns(string) 
   {@deleteRest {uriTemplate="{reqURL}"}};