profile image

Nafis Ayaz

C++ Software Engineer

Espresso: Get Started

  • Espresso - A web framework that compatible to C++14 and above, for that need to install latest version of GNU-GCC-7.5 or above. This tutorial will guide every single step for installation and will guide you to build a sample mini project with details about the code structure. Espresso+ compiler which combines espresso code and C++ and converts to executable code. In Espresso+ doesn't have C++ compiler, if there is no GNU compiler it is not possible to execute Espresso code anyways because Espresso framework is built on the top of C++14 and C++17 and so need to upgrade your C++ compiler to latest version. So Espresso framework could possible to embed C++ code also. The structure of semantics are very concise and readable that makes it's beauty. Distributed to apt repository from where can be installed on Linux system.

  • Check Gcc version already install, must have gcc-7.5 or above

    $  g++ -version    //   g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

    If there is not installed C++ compiler then execute following command as:

    $ sudo apt-get install gcc-7.5.0    //   For Installation
    $ sudo apt-get install gcc-7.5.0    //   For upgrade

    Once GCC compiler successfully installed then execute folowing command for Espresso Compiler as:

    $  sudo apt-get install espresso

    To know which version installed:

    $ espresso+   --version    //   installed version:  Espresso_1.0.0-v

    For testing whether Espresso is properly working or not, just copy the following code in test.es

    auto espresso = import("espresso").("http"); auto app = espresso(); app.get("/", function(request, response, err){      if(err == ERROR){        console.err("error: ", err );      }else{         response.send("hello world");      } }); app.run("8080", function(err){      console.log("Server started at ", 8080 ); });

    Now open the Terminal and run the following command as:

    $ espresso+  test.es
    $ ./espresso
       Server started at 8080

    Once Server is started the open chrome browser and paste the following queryline then you will get the message.

    localhost:8080


    The import is executed at runtime and return object which is by defualt auto type. object is one-time creation throughout the program, next time will give exeptions-throw. Espresso has many statndard libraries with no file-extension but user-defined library has to have file-extension i.e .es

    auto espresso = import("espresso");    //   Standard
    auto user-defined_lib = import("your-filename.es");
       //   User-defined

    After creation the object then operator () is called that returns the main espresso application object which is again one-time created.

    auto app = espresso();

    Espresso application object has Restfull Methods: GET, POST, DELETE and PUT Method that takes two arguments: a delimeter and a anonymous callback function. The anonymous callback function takes objects: request, response and error as parameters. The third argument is flag: error which is optional.

    app.get("/", function(request, response, err){
         if(err == ERROR){

           console.err("error: ", err );

         }else{

            response.send("hello world");

         }

    });

    Espresso application object has run function that takes two arguments: Port number and a anonymous callback function which takes a flag as a parameter.

    app.run("8080", function(err){
         console.log("Server started at ", 8080 );

    });