Deprecated Kalamar.api configuration key in favour of Kalamar.api_path

Change-Id: Iee8c4fc4e67ef1326e533d22b816a516fa6ac056
diff --git a/Changes b/Changes
index 0fb25b8..5d1d42d 100755
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.29 2018-08-30
+        - Deprecated Kalamar.api configuration key
+          in favor of Kalamar.api_path.
+
 0.28 2018-08-29
         - Introduced Widget based plugin system.
         - Added corpus statistics to VC (hebasta, #25).
diff --git a/README.md b/README.md
index 7e22507..fd76d50 100644
--- a/README.md
+++ b/README.md
@@ -83,20 +83,31 @@
 
 Kalamar will then be available at ```localhost:3000``` in your browser.
 
-By default, Kalamar tries to connect to ```localhost:9999```.
-You may change that endpoint to the KorAP API provider in in the configuration
-(see [Kustvakt](https://github.com/KorAP/Kustvakt) for further information).
+By default, Kalamar tries to connect to ```http://localhost:9999/api/```,
+followed by the most current version of the API.
+You may change that endpoint to the KorAP API provider in the configuration
+(see [Kustvakt](https://github.com/KorAP/Kustvakt) for further information)
+or by using the environment variable ```KALAMAR_API```.
 
 
 ## Configuration
 
 The basic configuration file is ```kalamar.conf```. To define derivations,
-create a configuration file with the pattern ```kalamar.[MYNAME].conf``` and
+create a configuration file with the pattern ```kalamar.myconf.conf``` and
 follow the descriptions in ```kalamar.conf```.
+
+To start Kalamar with a derivative configuration, set the ```MOJO_MODE```
+environment variable.
+
+```
+$ MOJO_MODE=myconf perl script/kalamar daemon
+```
+
 For client-side configurations, a file ```kalamar.conf.js``` can be
 introduced, that will be consulted during the build process, loading
 optional components using a ```require(...)``` directive (see example below).
 
+
 ### Localization
 
 To create a localized version of Kalamar, start the ```localize``` command
@@ -149,6 +160,7 @@
 See ```dev/js/src/hint/foundries``` for
 more optional foundries.
 
+
 ### Customization
 
 The landing page can be customized by overriding the
diff --git a/kalamar.conf b/kalamar.conf
index ada47bb..fc6a94c 100644
--- a/kalamar.conf
+++ b/kalamar.conf
@@ -29,13 +29,14 @@
 my $api = 'http://localhost:9999/api/';
 {
   Search => {
-    engine => 'Kalamar::API',
-    # Kustvakt server:
-    api => $ENV{'KALAMAR_API'} // $api
+    engine => 'Kalamar::API'
   },
   Kalamar => {
-    # Kustvakt server:
-    api => $ENV{'KALAMAR_API'} // $api,
+    # Backend server path
+    api_path => $ENV{'KALAMAR_API'} // $api,
+
+    # Backend API version
+    # api_version => '1.0',
 
     # In case, the user management of Kustvakt
     # is used, make this a true value
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 29b2e05..50ad7d9 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -1,12 +1,16 @@
 package Kalamar;
 use Mojo::Base 'Mojolicious';
 use Mojo::ByteStream 'b';
+use Mojo::URL;
 use Mojo::File;
 use Mojo::JSON 'decode_json';
 use Mojo::Util qw/url_escape/;
 
 # Minor version - may be patched from package.json
-our $VERSION = '0.28';
+our $VERSION = '0.29';
+
+# Supported version of Backend API
+our $API_VERSION = '1.0';
 
 # TODO: The FAQ-Page has a contact form for new questions
 # TODO: Embed query serialization
@@ -72,7 +76,33 @@
       });
   };
 
-  # Start fixture server
+  # Load Kalamar configuration
+  my $kalamar_conf = $self->config('Kalamar');
+
+  # Check for API endpoint and set the endpoint accordingly
+  if ($kalamar_conf->{api}) {
+
+    # The api endpoint should be defined as a separated path
+    # and version string
+    $self->log->info(
+      'Kalamar.api is deprecated in configurations '.
+        'in favor of Kalamar.api_path'
+      );
+  }
+
+  # Set from environment variable
+  elsif ($ENV{'KALAMAR_API'}) {
+    $kalamar_conf->{api} = $ENV{'KALAMAR_API'};
+  }
+
+  # API is not yet set - define
+  else {
+    $kalamar_conf->{api} =
+      Mojo::URL->new($kalamar_conf->{api_path})->path('v' . ($kalamar_conf->{api_version} // $API_VERSION) . '/')->to_string;
+  };
+
+
+  # Start fixture server for testing purposes
   if ($self->mode eq 'test') {
 
     $self->log->info('Mount test server');
@@ -86,8 +116,7 @@
     });
 
     # Fix api endpoints
-    $self->config('Kalamar')->{api} = $mount_point;
-    $self->config('Search')->{api} = $mount_point;
+    $kalamar_conf->{api} = $mount_point;
   }
 
   # Add development path
@@ -95,6 +124,11 @@
     push @{$self->static->paths}, 'dev';
   };
 
+  # Check search configuration
+
+  # Set endpoint
+  $self->config('Search')->{api} //= $kalamar_conf->{api};
+
   # Client notifications
   $self->plugin(Notifications => {
     'Kalamar::Plugin::Notifications' => 1,
diff --git a/package.json b/package.json
index 7011b99..b26b983 100755
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "Kalamar",
   "description": "Mojolicious-based Frontend for KorAP",
   "license": "BSD-2-Clause",
-  "version": "0.28.2",
+  "version": "0.29.0",
   "pluginVersion": "0.1",
   "repository" : {
     "type": "git",