2017 October Release

Web ServicesPermanent link for this heading

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:

  • Create a web service as a new WebServiceDefinition instance
  • Create a web service by extending the WebServiceConfiguration

Web Service DefinitionPermanent link for this heading

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 {
  webserviceactions<webserviceoperation, webserviceaction> = {

    {"MyConcreteWebService", MyWebserviceAction}

  }

}

You can call the web service via the following URL:

https://<host>/<vdir>/wsjson/MYDEMOAPP_111_100_MyWebServices/MyOperation

Web Service ConfigurationPermanent link for this heading

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 {
  FSCOWS@1.1001:friendlyurlconfig<FSCOWS@1.1001:friendlyurlurl,

    FSCOWS@1.1001:friendlyurlaction,

    FSCOWS@1.1001:friendlyurlincont,

    FSCOWS@1.1001:friendlyurloutcont,

    FSCOWS@1.1001:friendlyurlparams<FSCOWS@1.1001:friendlyurlparamnr,      

      FSCOWS@1.1001:friendlyurlparamname>,

    FSCOWS@1.1001:friendlyurlallowedmethods,

    FSCOWS@1.1001:friendlyurlswc> =

  {  

    {

      "mywebservice",

      MyWebserviceOperation,

      null,

      null,

      null,

      {

        HTTPMETHOD_GET

      },

      MYDEMOAPP@111.100

    }

  }

}

You can call the web service with the following URL:

https://<host>/<vdir>/mywebservice

RESTful Web ServicesPermanent link for this heading

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 {
  FSCOWS@1.1001:friendlyurlconfig<FSCOWS@1.1001:friendlyurlurl,

    FSCOWS@1.1001:friendlyurlaction,

    FSCOWS@1.1001:friendlyurlincont,

    FSCOWS@1.1001:friendlyurloutcont,

    FSCOWS@1.1001:friendlyurlparams<FSCOWS@1.1001:friendlyurlparamnr,      

      FSCOWS@1.1001:friendlyurlparamname>,

    FSCOWS@1.1001:friendlyurlallowedmethods,

    FSCOWS@1.1001:friendlyurlswc> =

  {  

    {

      "mywebservice",

      MyWebserviceOperation,

      null,

      null,

      null,
      {

        HTTPMETHOD_GET,

        HTTPMETHOD_PUT,

        HTTPMETHOD_DELETE,

        HTTPMETHOD_OPTIONS

      },

      MYDEMOAPP@111.100

    }

  }

}

Now you have to create the concrete web service:

Example

public MyWebserviceAction () {
  variant Object {

    impl = expression {

      coort.Trace("incoming method", #TV.TV_FRIENDLYURL_INCOMING_METHOD);      

      if (#TV.TV_FRIENDLYURL_INCOMING_METHOD == “GET”) { /* your code */  }
      if (#TV.TV_FRIENDLYURL_INCOMING_METHOD == “DELETE”) { /* your code */  }

      if (#TV.TV_FRIENDLYURL_INCOMING_METHOD == “PUT”) { /* your code */  }

      if (#TV.TV_FRIENDLYURL_INCOMING_METHOD == “POST”) { /* your code */  }

    }

  }

}

JSONPPermanent link for this heading

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.

Create an HTTP RequestPermanent link for this heading

With app.ducx you can perform an HTTP request to gather information, for example from external web services.

Example

usecase DoHttpRequest() {
  variant Object {

    impl = expression {

      dictionary resphead;
      content response;

      string url="http://www.google.com";

      coouser.FSCOWS@1.1001:SendHttpRequest("GET",url,,,&resphead,&response);

    }

  }

}