A Vely application can run as a web application or a command line program, or both - such as when some requests can be either fulfilled through web interface or the command line. Note that Vely produces two separate executables: a FastCGI
server one and a command line one - they are different because command line interface does not need the FastCGI library and code that uses it, and thus is smaller.
The name of the command-line executable is the same as the application name, and its path is (assuming <app name> is the application name):
/var/lib/vv/bld/<app name>/<app name>
A command line program works the same way as a FastCGI executable, and the output is the same, except that it is directed to stdout (standard output) and stderr (standard error).
To specify the exit code of a command line program, use exit-code
. To exit the program, use exit-request
, or otherwise the program will exit when it reaches the end of a request
Executing a request
A command line program must obtain its request URL via environment variables, for example if the application name is "stock", here is how to execute it with input-param
eter "action" having a value of "show":
At the minimum, you must set environment variables REQUEST_METHOD and QUERY_STRING.
Suppressing HTTP header output for the entire application
If you wish to suppress the output of HTTP headers for all requests, set environment variable VV_SILENT_HEADER to "yes" before executing the program:
This will suppress the effect of out-header
, or for any other case where headers are output. This has the same effect as silent-header
, the only difference is that it applies to the entire application.
URL-encoding the input
QUERY_STRING must be formatted to be a valid URL; for example, data that contains special characters (like "&" or "?") must be URL-encoded, for instance:
In this case, field "data" has value of "a?b", where special character "?" is encoded as "%3F".
To make sure all your input parameters are properly URL-encoded, use Vely's v1 code processor:
$($(vv -l)/v1 -urlencode '<your data>')
For instance, to encode "a?=b" as a parameter:
export QUERY_STRING="req=stock&act=show&data=$($(vv -l)/v1 -urlencode 'a?=b')"
POST requests must be provided on a standard input, usually by piping the output of another program into your command-line program.
You can also use a command line program with CGI
(Common Gateway Interface). Note that CGI programs generaly exhibit much lower performance; use CGI only when warranted by a specific situation.