====== Vortex Integration via REST Webservices ====== Since version 1.2 the Vortex supports integration via REST Webservices. This chapter will explain how to configure, maintain and use this integration interface in depth. ===== Overview ===== The REST webservice is called using the URL of the Vortex instance with an appended ///rest// path, followed by the Database Instance and finally the name of the REST function and its arguments. Example: http://my.vortex.net/rest/MyDBI/getCustomer/?idcustomer=12345 Accessing this URL will return the result of calling the //getCustomer// method in the //RESTService// class which is implemented in the /script folder of the DBI. ===== Setting up a Vortex Webservice ===== The REST service needs no setup. ===== Implementing the RESTService class ===== The behaviour of the REST Service is defined by the //RESTService// class, which is implemented as a DBI Script. This class is instanciated once for every call to the REST service. The constructor is passed the request method used to access the service: GET, POST, PUT or DELETE. The REST service then logs in to the Vortex using the given criteria in the public constants //RESTUser// and //RESTPassword//. Without theese constants set the service will fail. If the service should run as some other user depending on login calls to the service, this has to be solved in the script using the login methods of the User class. All the methods that should be accessed using the REST Service must be implemented as public methods of the //RESTService// class. All the parameters supplied in the URL will be sent to the metod in one associative array. Implementing the method //getCustomer// in the example above would look something like class RESTService { const RESTUser = "restuser"; const RESTPassword = "restpass"; private $reqMethod; public function __construct( $reqMethod ) { $this->reqMethod = $reqMethod; } public function getCustomer( $arguments ) { if( !isset( $arguments['idcustomer'] ) ) throw new Exception( "No user id supplied" ); $f = new FilterData( "customer" ); $f->add( "idcustomer", FilterData::EQUALS, $arguments['idcustomer'] ); $trs = $f->getFilter()->getTableRecords(); if( count( $trs ) == 0 ) return ""; return $trs->toXML(); } } Before calling the //getCustomer// method the Vortex RESTServiceHandler will try to call a request method specific method called //getCustomer_GET// for GET operations, //getCustomer_POST// for POST operations and so forth. If that method does not exist within the RESTService class //getCustomer// will be called.