Drogon is a Web Framework written with C++ that works on both C++14 and C++17 versions.
The TechEmpower website (ranking link) has some benchmark services that test the performance of some technologies and among these tests, it analyzed the performance of Web Frameworks for Back-end and Drogon was the first placed in tests with 105 frameworks, among them: Rails, Django, NestJS, Laravel and others.
To install, you will first need some dependencies at compile time and at run time. They are:
For systems that use APT: Debian, Ubuntu, Mint and derivatives, just run this command below:
For systems using Portage: Gentoo, Funtoo and derivatives:
For systems that use RPM: Fedora, Red Hat and derivatives
If in the future you will develop applications that use databases (which I believe so), it is extremely important that you install them before installing Drogon. It can be one of those listed below:
For this basic example we are going to create a static page without querying the database
Now my my-project has the following files:
The original main.cc
file is on port 80
, but this could be a conflict on your system. Then change, for example, to port 8080
.
If you also have a problem with port
8080
, use port1024
or try a port bigger than it that is not being used, to find out if it is being used use nmap, for example, to find out. Do not use ports less than 1024 as they should only be used for privileged users (root
, for example).
With the following content:
And compile:
Now run the binary file that was created inside the directory you are in (build
). In my case, as I called the project my-project
, there is a binary with that name, so just run it:
Access the address: http://0.0.0.0:8080/ . And accessing it you will already find a beautiful 404
:
To “take down” the server’s execution, press: Ctrl + C
. But that means it’s already working. Then just add an HTML page (still inside the build
directory) and access it again:
And go to: http://0.0.0.0:8080/
We are going to create a test controller named ListController
just to display the phrase: “My controller list”. At the root of your project, enter the directory: controller
and run the following command to create the controller.
The output should be:
create a http simple controller: ListController.
Two files were created: ListController.cc
and ListController.h
First, let’s edit the file: ListController.h
and add these two lines:
The final file looks like this:
And the ListController.cc
file should look like this:
Recompile the project and access:
Now both at the root (http://localhost:8080/ via get or post) and at http://localhost:8080/list we will get content.
If you are using Postman you will notice that the root will return the information for both GET and POST, but the /list
will only return for GET.
The address of the official Drogon on GitHub is: https://github.com/an-tao/drogon, there you can get information of all documentation to install and develop your web applications.
The video is in Brazilian Portuguese, but you can use subtitles and translate into your language.