This chapter provides an overview of how to write your own web services with Fabasoft app.ducx.
Basically there are two ways to create a new web service:
Creating a web service with a new instance of WebServiceDefinition is the recommended way. You just have to implement a use case and then expose it via a WebServiceDefinition.
Example |
instance WebServiceDefinition MyWebServices { |
You can call the web service via the following URL:
https://<host>/<vdir>/wsjson/MYDEMOAPP_111_100_MyWebServices/MyOperation
Extending the WebServiceConfiguration is not as simple as creating a WebServiceDefintion but it allows you to control the input and output handling or creation of RESTful web services.
The following example shows a configuration of a web service:
Example |
extend instance FSCOWS@1.1001:WebServiceConfiguration { |
You can call the web service with the following URL:
https://<host>/<vdir>/mywebservice
If you are not familiar with the REST architecture please check out this Wikipedia article (http://de.wikipedia.org/wiki/Representational_State_Transfer).
Basically, you can put this architecture into practice by extending the WebServiceConfiguration by adding the typical REST http verbs (we call it friendlyurlallowedmethods):
Example |
extend instance FSCOWS@1.1001:WebServiceConfiguration { |
Now you have to create the concrete web service:
Example |
public MyWebserviceAction () { if (#TV.TV_FRIENDLYURL_INCOMING_METHOD == “GET”) { /* your code */ } |
If you are not familiar with JSONP, consult: http://en.wikipedia.org/wiki/JSONP. Basically, all web services defined by WebServiceDefinition support JSONP.
You can set the JSONP parameter in GET requests. The parameter contains the name of the callback function that should be executed when the web service has finished.
Example |
https://at.cloud.fabasoft.com/folio/wsjson/FSCTEAMROOM_1_1001_TeamRoomWebService/TeamRoomInvitations?jsonp=myCallbackFunction This returns: myCallbackFunction({"results":0,"invitations":null}) |
Note that by using JSONP you are limited to GET requests, since this technique only includes an “external” script and you cannot “include” a script, for example with a POST request. Parameters can therefore not be passed within the request body, but only in the URL.
With app.ducx you can perform an HTTP request to gather information, for example from external web services.
Example |
usecase DoHttpRequest() { |