Difference between revisions of "Install REST"

From xPL
Jump to: navigation, search
(Install Mojolicious Lite)
Line 44: Line 44:
 
For Debian and related distributions such as Ubuntu, a dedicated option is to use:
 
For Debian and related distributions such as Ubuntu, a dedicated option is to use:
 
  sudo apt install libmojolicious-perl
 
  sudo apt install libmojolicious-perl
 +
 +
Once installed, one can test the service with:
 +
SERVICE_DIRECTORY='/home/control/Documents/Controls'
 +
morbo $SERVICE_DIRECTORY/rest.pl
 +
This starts an HTTP service, usually on port 3000.
 +
Each time the Perl script is updated, the service is updated too.
 +
Interpretor errors are displayed in the terminal where the [https://mojolicious.org/perldoc/morbo morbo] runs.
 +
 +
Test the service in another terminal window:
 +
curl -X GET localhost:3000/test/hello/world?'a=b&c=d'
 +
 +
Check the result in:
 +
cat /tmp/rest.log
  
 
[[Category: all]] [[Category: install]] [[Category: web]]
 
[[Category: all]] [[Category: install]] [[Category: web]]

Revision as of 13:11, 12 May 2020

Controlling the home from distance can be made via standard web access methods such as the RESTful API.

Different options are available for the implementation of such a service:

  • Installing a web server and writing CGI scipts
  • Writing scripts serving a TCP socket and complying to the HTTP scheme
  • Using a framework such as:

I have chosen Mojolicious Lite for its simplicity and the ease of development.

Before all, make sure you have installed an xPL hub.


Install Mojolicious Lite

Mojolicious::Lite can be installed with the standard CPAN method. For Debian and related distributions such as Ubuntu, a dedicated option is to use:

sudo apt install libmojolicious-perl

Once installed, one can test the service with:

SERVICE_DIRECTORY='/home/control/Documents/Controls'
morbo $SERVICE_DIRECTORY/rest.pl

This starts an HTTP service, usually on port 3000. Each time the Perl script is updated, the service is updated too. Interpretor errors are displayed in the terminal where the morbo runs.

Test the service in another terminal window:

curl -X GET localhost:3000/test/hello/world?'a=b&c=d'

Check the result in:

cat /tmp/rest.log