Drogon C++, The Fastest Web Framework in the World
It was first placed in tests with 105 frameworks, among them: Rails, Django, NestJS, Laravel and others.
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.
- The name Drogon comes from the dragon called Drogon from the Game of Thrones series.
- It is available for Linux, macOS, FreeBSD, OpenBSD and Windows.
- Uses an epoll-based non-blocking I/O network library (and in the case for macOS and FreeBSD uses kqueue).
- It supports the HTTP 1.0 and 1.1 protocol (for both server-side and client-side);
- It has support for cookies and embedded sessions.
- It also has support for: HTTPS (with OpenSSL), WebSocket, request and response for JSON format, widely used for Restful API
- In addition to AOP with joinpoints and among several other features.
To install, you will first need some dependencies at compile time and at run time. They are:
For systems using Portage: Gentoo, Funtoo 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
1. Example 1 (The basics of the basics)
1.1 - Creating the project
Now my my-project has the following files:
1.2 - Changing the main.cc file port
main.cc file is on port
80, but this could be a conflict on your system. Then change, for example, to port
If you also have a problem with port
8080, use port
1024or 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:
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
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/
2. Creating a Controller
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:
2.1 - Editing the files
First, let’s edit the file:
ListController.h and add these two lines:
The final file looks like this:
ListController.cc file should look like this:
Recompile the project and access:
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.
If you want to watch a video featuring all the resources provided in this article, watch the video below:
The video is in Brazilian Portuguese, but you can use subtitles and translate into your language.