{"id":64617,"date":"2022-05-26T09:01:30","date_gmt":"2022-05-26T09:01:30","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=64617"},"modified":"2022-05-26T09:01:30","modified_gmt":"2022-05-26T09:01:30","slug":"write-c-applications-using-vely-on-linux","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=64617","title":{"rendered":"Write C applications using Vely on Linux"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Write C applications using Vely on Linux<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/vely\" class=\"username\">Sergio Mijatovic<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Thu, 05\/26\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-70022\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>Vely is a tool for writing web and command-line applications in C. Vely combines high performance and the low footprint associated with C programming with ease of use and improved safety reminiscent of languages like PHP. It&#8217;s free and open source software, and licensed under GPLv3 and LGPL 3 for libraries, so you can even build commercial software with it.<\/p>\n<p>Vely works on major Linux distributions and processor architectures. You can use webservers, such as Apache, Nginx, or others, and databases such as MariaDB, PostgreSQL, and SQLite.<\/p>\n<p>You can use Vely for web applications, command-line programs, as middleware, database applications, services software, data integration, IoT (Internet of Things), and anywhere else. It&#8217;s well suited for the cloud, works easily in a container, and, due to low resource requirements, it&#8217;s also a good choice when memory and processing power are at a premium.<\/p>\n<h2>Install Vely<\/h2>\n<p>To try Vely, install the Apache webserver and <a href=\"https:\/\/www.redhat.com\/sysadmin\/mysql-mariadb-introduction?intcmp=7013a000002qLH8AAM\" target=\"_blank\" rel=\"noopener\">MariaDB database<\/a>. You can use a different webserver and database, and the setup would be similar, but in this example, I use Apache and MariaDB.<\/p>\n<p>Next, install Vely. On Linux use a package manager such as <code>dnf<\/code> or <code>apt<\/code>.<\/p>\n<h2>Stock tickers project<\/h2>\n<p>This example saves the names of stock tickers and their prices so you can view them in a list.<\/p>\n<p>Start by creating <code>stock.v<\/code> file, and paste this code into it:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"text geshifilter-text\">#include \"vely.h\"<br><br>\nvoid stock() {<br>\n\u00a0 \u00a0out-header default<br>\n\u00a0 \u00a0@<br>\n\u00a0 \u00a0 \u00a0 \u00a0@<br>\n\u00a0 \u00a0 \u00a0 \u00a0input-param action<br>\n\u00a0 \u00a0 \u00a0 \u00a0input-param stock_name<br>\n\u00a0 \u00a0 \u00a0 \u00a0input-param stock_price<br>\n\u00a0 \u00a0 \u00a0 \u00a0if (!strcmp (action, \"add\")) {<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Add to stock table, update if stock exists<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 run-query#add_data@db = \"insert into stock (stock_name,<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 stock_price) values ('%s', '%s') on duplicate key <br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 update stock_price='%s'\" : stock_name, stock_price, <br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 stock_price<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0end-query<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0error#add_data to define err<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (strcmp (err, \"0\")) {<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0report-error \"Cannot update stock price, error [%s]\", err<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<div><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 @Stock price updated!<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/div><br>\n\u00a0 \u00a0 \u00a0 \u00a0} else if (!strcmp (action, \"show\")) {<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ Show stock names and values<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<table><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<tr><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<td>Stock name<\/td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<td>Stock price<\/td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/tr><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0run-query#show_data@db = \"select stock_name, <br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 stock_price from stock\" output stock_name, <br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 stock_price<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<tr><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0query-result#show_data, stock_name<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0query-result#show_data, stock_price<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/td><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/tr><br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0end-query<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<\/table><br>\n\u00a0 \u00a0 \u00a0 \u00a0} else {<br>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@<div>Unrecognized request!<\/div><br>\n\u00a0 \u00a0 \u00a0 \u00a0}<br>\n\u00a0 \u00a0 \u00a0 \u00a0@<br>\n\u00a0 \u00a0@<br>\n}<\/div><\/div><\/pre>\n<h2>Build the database<\/h2>\n<p>For this example, create a database named <code>dbstock<\/code>, owned by user <code>vely<\/code> with the password <code>your_password<\/code>. These are arbitrary names, and in real life, you can use whatever values you want, as long as they&#8217;re consistent throughout your code.<\/p>\n<p>First, log in to the MariaDB database as root and execute this:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"sql geshifilter-sql\"><span class=\"kw1\">CREATE<\/span> <span class=\"kw1\">DATABASE<\/span> <span class=\"kw1\">IF<\/span> <span class=\"kw1\">NOT<\/span> <span class=\"kw1\">EXISTS<\/span> dbstock;<br><span class=\"kw1\">FLUSH<\/span> privileges;<br><span class=\"kw1\">CREATE<\/span> <span class=\"kw1\">USER<\/span> <span class=\"kw1\">IF<\/span> <span class=\"kw1\">NOT<\/span> <span class=\"kw1\">EXISTS<\/span> vely@localhost <span class=\"kw1\">IDENTIFIED<\/span> <span class=\"kw1\">BY<\/span> <span class=\"st0\">'your_password'<\/span>;<br><span class=\"kw1\">FLUSH<\/span> privileges;<br><span class=\"kw1\">GRANT<\/span> <span class=\"kw1\">ALL<\/span> privileges <span class=\"kw1\">ON<\/span> dbstock<span class=\"sy0\">.*<\/span> <span class=\"kw1\">TO<\/span> vely@localhost;<br><span class=\"kw1\">FLUSH<\/span> privileges;<br>\nexit;<\/div><\/div><\/pre>\n<p>Now log in to MariaDB again and set the current database:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>mysql <span class=\"re5\">-u<\/span> vely -pyour_password<\/code><\/span><\/pre>\n<p>Now you can create the database objects needed for the application. You need a <code>stock<\/code> table in the <code>dbstock<\/code> database for this example.<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"sql geshifilter-sql\"><span class=\"kw1\">USE<\/span> dbstock;<br><span class=\"kw1\">CREATE<\/span> <span class=\"kw1\">TABLE<\/span> <span class=\"kw1\">IF<\/span> <span class=\"kw1\">NOT<\/span> <span class=\"kw1\">EXISTS<\/span> stock <span class=\"br0\">(<\/span>stock_name <span class=\"kw1\">VARCHAR<\/span><span class=\"br0\">(<\/span><span class=\"nu0\">100<\/span><span class=\"br0\">)<\/span> <span class=\"kw1\">PRIMARY<\/span> <span class=\"kw1\">KEY<\/span><span class=\"sy0\">,<\/span> stock_price <span class=\"kw1\">BIGINT<\/span><span class=\"br0\">)<\/span>;<\/div><\/div><\/pre>\n<p>Finally, create a database configuration file named <code>db<\/code> so that your application can log into the database. You must call it <code>db<\/code> because that&#8217;s what the code in <code>stock.v<\/code> uses. For instance:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"sql geshifilter-sql\"><span class=\"br0\">[<\/span><span class=\"sy0\">...<\/span><span class=\"br0\">]<\/span><br>\nrun<span class=\"sy0\">-<\/span>query#add_data@db <span class=\"sy0\">=<\/span> <span class=\"st0\">\"insert into stock ...\"<\/span><br><span class=\"br0\">[<\/span><span class=\"sy0\">...<\/span><span class=\"br0\">]<\/span><\/div><\/div><\/pre>\n<p>The database name is preceded by the <code>@<\/code> sign, in this case, <code>@db<\/code>, so the name of the database configuration file is <code>db<\/code>. As with other values, you can name your database configuration file whatever you want, as long as your code is consistent.<\/p>\n<p>Here&#8217;s the configuration for the <code>db<\/code> file:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"ini geshifilter-ini\"><span class=\"re0\"><span class=\"br0\">[<\/span>client<span class=\"br0\">]<\/span><\/span><br><span class=\"re1\">user<\/span><span class=\"sy0\">=<\/span><span class=\"re2\">vely<\/span><br><span class=\"re1\">password<\/span><span class=\"sy0\">=<\/span><span class=\"re2\">your_password<\/span><br><span class=\"re1\">database<\/span><span class=\"sy0\">=<\/span><span class=\"re2\">dbstock<\/span><\/div><\/div><\/pre>\n<p>The above is a standard MariaDB <a href=\"https:\/\/mariadb.com\/kb\/en\/configuring-mariadb-connectorc-with-option-files\/#options\" target=\"_blank\" rel=\"noopener\">client options file<\/a>. Vely uses native database connectivity, so you can specify any options a given database allows.<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">Programming and development<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/?intcmp=7016000000127cYAAQ\">Red Hat Developers Blog<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheets?intcmp=7016000000127cYAAQ\">Programming cheat sheets<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/www.redhat.com\/en\/services\/training\/learning-subscription?intcmp=7016000000127cYAAQ\">Try for free: Red Hat Learning Subscription<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/bash-programming-guide?intcmp=7016000000127cYAAQ\">eBook: An introduction to programming with Bash<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/bash-shell-cheat-sheet?intcmp=7016000000127cYAAQ\">Bash shell scripting cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/e-books\/modernizing-enterprise-java?intcmp=7016000000127cYAAQ\">eBook: Modernizing Enterprise Java<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>Build the application<\/h2>\n<p>Next, you can create your Vely application. For this example, you&#8217;re going to create a web app called <code>stockapp<\/code>:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> vf <span class=\"re5\">-i<\/span> <span class=\"re5\">-u<\/span> $<span class=\"br0\">(<\/span><span class=\"kw2\">whoami<\/span><span class=\"br0\">)<\/span> stockapp<\/code><\/span><\/pre>\n<p>This creates an application home under the Vely directory (<code>\/var\/lib\/vv<\/code>) and performs the required application setup steps for you.<\/p>\n<p>To build your application, use the <code>vv<\/code> command:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>vv <span class=\"re5\">-q<\/span> <span class=\"re5\">--db<\/span>=mariadb:db stockapp<\/code><\/span><\/pre>\n<p>Here&#8217;s what each option means:<\/p>\n<ul>\n<li><code>-q<\/code> builds an application<\/li>\n<li><code>--db<\/code> specifies the database to be used (<code>mariadb:db<\/code>, as specified in your configuration file)<\/li>\n<li><code>stockapp<\/code> is the application name<\/li>\n<\/ul>\n<p>You can actually use any number of databases and different vendors in your application. This example is simple, though, so you only need one database. Vely has many other useful options you can use, but this is sufficient for now.<\/p>\n<h2>Configure web access<\/h2>\n<p>To access your application via a web browser or various web clients, you need to set up a webserver. It can be Apache, Nginx, or any other server that supports FastCGI proxying (most, if not all, webservers and load balancers do this). Here, I will set up Apache, but the setup is similar for other webservers.<\/p>\n<p>The <code>proxy<\/code> and <code>proxy_fcgi<\/code> modules are installed and enabled by default on the Fedora install of the Apache web server, but you must enable them on Debian-based systems (like Ubuntu):<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ <span class=\"kw2\">sudo<\/span> a2enmod proxy<br>\n$ <span class=\"kw2\">sudo<\/span> a2enmod proxy_fcgi<br>\n$ <span class=\"kw2\">sudo<\/span> systemctl restart apache2<\/div><\/div><\/pre>\n<p>If you&#8217;re not on a Debian-based system, you can enable an Apache module by adding it to the Apache configuration file or in a file in the <code>\/etc\/httpd\/conf.modules.d\/<\/code> directory, depending on your distribution&#8217;s configuration.<\/p>\n<p>Next, open your Apache configuration file in a text editor. For example, on a Debian-based system:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">vi<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>apache2<span class=\"sy0\">\/<\/span>apache2.conf<\/code><\/span><\/pre>\n<p>On a Fedora system (including Red Hat Enterprise Linux and CentOS):<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">vi<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>httpd<span class=\"sy0\">\/<\/span>conf<span class=\"sy0\">\/<\/span>httpd.conf<\/code><\/span><\/pre>\n<p>Add this line to the end of the file:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"text geshifilter-text\">ProxyPass \"\/stockapp\" unix:\/\/\/var\/lib\/vv\/stockapp\/sock\/sock|fcgi:\/\/localhost\/stockapp<\/code><\/span><\/pre>\n<p>Depending on your webserver configuration, there may be a better place to add the <code>ProxyPass<\/code> directive. For this example, though, the above is sufficient.<\/p>\n<p>Save the file and restart the webserver. On Fedora-based systems:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> systemctl restart httpd<\/code><\/span><\/pre>\n<p>On Debian-based systems:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> systemctl restart apache2<\/code><\/span><\/pre>\n<p>In this case, you&#8217;re connecting to your application through a socket, but you can use a TCP port instead (which comes in handy when your application resides in a container or something similar).<\/p>\n<h2>Run the application<\/h2>\n<p>Start the application server for your application:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>vf stockapp<\/code><\/span><\/pre>\n<p>By default, this runs anywhere from 0 to 20 server processes for your application, depending on the load. When the user load is low, your application uses virtually no memory at all.<\/p>\n<p>That was it! Navigate to <a href=\"http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=add&amp;stock_name=XYZ&amp;stock_price=440\">http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=add&amp;stock_name=XYZ&amp;stock_pri\u2026<\/a> in your web browser to see the application.<\/p>\n<p>You&#8217;ve just updated the stock price for ticker &#8220;XYZ&#8221; to 440. Try different tickers and prices to build a list of stocks, which you can view with the URL <a href=\"http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=show\">http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=show<\/a>.<\/p>\n<p>Congratulations, you&#8217;ve created your first Vely application, reverse proxied behind a web server.<\/p>\n<p>You can also view the output without a graphical browser by <a href=\"https:\/\/opensource.com\/article\/20\/5\/curl-cheat-sheet\" target=\"_blank\" rel=\"noopener\">using curl<\/a>:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ curl <span class=\"re5\">-s<\/span> <br><span class=\"st0\">\"http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=add&amp;stock_name=XYZ&amp;stock_price=440\"<\/span><br>\n$ curl <span class=\"re5\">-s<\/span> <span class=\"st0\">\"http:\/\/127.0.0.1\/stockapp?req=stock&amp;action=show\"<\/span><\/div><\/div><\/pre>\n<h2>Run the application from the terminal<\/h2>\n<p>You can run your application from the terminal, too. A terminal command is always made along with the FastCGI application server, and it&#8217;s named the same as your application (in this case, <code>stockapp<\/code>). It works exactly the same as the web app. You can write some requests to your application to be fulfilled as web requests and others to run from the command-line. To do that, you provide the request as environment variables. For instance, to output the list of stocks as HTML, type:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ <span class=\"kw3\">export<\/span> <span class=\"re2\">REQUEST_METHOD<\/span>=GET<br>\n$ <span class=\"kw3\">export<\/span> <span class=\"re2\">QUERY_STRING<\/span>=<span class=\"st0\">\"req=stock&amp;action=show\"<\/span><br>\n$ <span class=\"sy0\">\/<\/span>var<span class=\"sy0\">\/<\/span>lib<span class=\"sy0\">\/<\/span>vv<span class=\"sy0\">\/<\/span>bld<span class=\"sy0\">\/<\/span>stockapp<span class=\"sy0\">\/<\/span>stockapp<\/div><\/div><\/pre>\n<p>To suppress HTTP headers, use:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ <span class=\"kw3\">export<\/span> <span class=\"re2\">VV_SILENT_HEADER<\/span>=<span class=\"kw2\">yes<\/span><br>\n$ <span class=\"sy0\">\/<\/span>var<span class=\"sy0\">\/<\/span>lib<span class=\"sy0\">\/<\/span>vv<span class=\"sy0\">\/<\/span>bld<span class=\"sy0\">\/<\/span>stockapp<span class=\"sy0\">\/<\/span>stockapp<\/div><\/div><\/pre>\n<h2>How Vely works<\/h2>\n<p>Your application works by processing requests and sending back replies. A request is one of two HTTP methods: GET or POST.<\/p>\n<p>A request always has a parameter <code>req<\/code>. In the example here, its value is <code>stock<\/code>. That means source code compiled from file <code>stock.v<\/code> is called automatically to handle such a request.<\/p>\n<p>A source file like this can do many different things, all grouped logically under a single request. Here, you have another parameter <code>action<\/code>, which can have a value of <code>add<\/code> (to add or update a stock) or <code>show<\/code> (to show a list of stocks). You specify <code>stock_name<\/code> and <code>stock_price<\/code> parameters when adding or updating. Pretty easy stuff. Other than <code>req<\/code>, you can choose parameter names however you wish.<\/p>\n<p>Looking at the code in <code>stock.v<\/code>, it&#8217;s simple to follow. You use the <a href=\"https:\/\/vely.dev\/input-param.html\" target=\"_blank\" rel=\"noopener\">input-param<\/a> construct to get the values for your input parameters. Yes, those strange things in the C code that aren&#8217;t C are <a href=\"https:\/\/vely.dev\/language_constructs.html\" target=\"_blank\" rel=\"noopener\">Vely language constructs<\/a>, and they do lots of useful stuff for you, such as <a href=\"https:\/\/vely.dev\/run-query.html\" target=\"_blank\" rel=\"noopener\">run-query<\/a>, which (as you might expect from the name) runs your queries. An easy one is <code>@<\/code>, which is an <a href=\"https:\/\/vely.dev\/output_construct.html\" target=\"_blank\" rel=\"noopener\">output construct<\/a>. String handling is made simple and reliable without worrying about buffer overruns. Check out the <a href=\"https:\/\/vely.dev\/reference.html\" target=\"_blank\" rel=\"noopener\">full reference of Vely constructs<\/a> to understand Vely&#8217;s capabilities.<\/p>\n<p>Vely converts all constructs in your code into pure C and makes a native executable that is very small and fast. Your application runs as several FastCGI server processes, which stay resident in memory while accepting and processing requests. All of these processes work in parallel.<\/p>\n<p>For more info, see <a href=\"https:\/\/vely.dev\/how_vely_works.html\" target=\"_blank\" rel=\"noopener\">how Vely works<\/a> and read more about <a href=\"https:\/\/vely.dev\/vely_architecture.html\" target=\"_blank\" rel=\"noopener\">Vely architecture<\/a>.<\/p>\n<h2>Manage strings and memory<\/h2>\n<p>Vely has automatic garbage collection for all of its constructs. In fact, most of the time, you shouldn&#8217;t need to free memory at all, so application development is even simpler. Leave that to Vely and enjoy computing free of memory leaks and far fewer memory issues than you might expect. String constructs such as <code>write-string<\/code> make it safe, fast, and easy to create complex strings just as they do simple ones.<\/p>\n<h2>FastCGI program manager<\/h2>\n<p>Even if you don&#8217;t want to develop your own applications with Vely, you can use <code>vf<\/code>, <a href=\"https:\/\/vely.dev\/plain_C_FCGI.html\" target=\"_blank\" rel=\"noopener\">Vely&#8217;s FastCGI program manager<\/a>, with any generic FastCGI program, not just those created with Vely.<\/p>\n<h2>Want to learn more about Vely?<\/h2>\n<p>I sometimes get asked about the project name. <em>Vely<\/em> is short for <em>Vel(ocit)y<\/em>. It&#8217;s fast to program with, fast to understand code and maintain, and fast (and small!) at run time. It&#8217;s even easy to containerize.<\/p>\n<p>Check out the documentation at <a href=\"http:\/\/vely.dev\/\" target=\"_blank\" rel=\"noopener\">vely.dev<\/a>, which features downloads and examples that go beyond the introduction this article provides.<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Vely is an open source tool for writing web and command-line applications in C on major Linux distributions.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/05\/OSDC_women_computing_2.png\" width=\"520\" height=\"292\" alt=\"Woman sitting in front of her computer\" title=\"Women in computing and open source\" loading=\"lazy\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Ray Smith<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/programming\" hreflang=\"en\">Programming<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-listicles field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/22\/3\/how-c-programming-language-has-grown\" hreflang=\"en\">How the C programming language has grown<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/20\/10\/mariadb-mysql-linux\" hreflang=\"und\">Install MariaDB or MySQL on Linux<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/05\/cc-by-sa--36.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write C applications using Vely on Linux Sergio Mijatovic Thu, 05\/26\/2022 &#8211; 03:00 Register or Login to like Register or Login to like Vely is a tool for writing web and command-line applications in C. Vely combines high performance and the low footprint associated with C programming with ease of use and improved safety reminiscent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":64618,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-64617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/64617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64617"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/64617\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/64618"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}