
Drogon – C++14/17-based rapid HTTP and web application framework - dragonsh
https://github.com/an-tao/drogon
======
cheez
Always glad to see another contender!

The documentation is very thorough and gives a good overview. Every library
should be like this.

That being said, I have written a lot of HTTP servers and clients in C++ so I
have some opinions on the design of this library.

Modern C++ really tries to avoid preprocessor macros for the reason that it's
really hard to know what is going on. Macros can do anything. So I would
suggest you get rid of the code generation including dragon_ctl. Write a
library that doesn't need code generation. C++17 has all the tools needed to
do this.

~~~
billconan
I have a question. I have also implemented my C++ web framework. I found it is
difficult to conform to http spec. There doesn't seem to be a Conformance
test?

How do people do it?

~~~
cheez
If you're writing one for general consumption, I wish you luck.

------
_wldu
Since you are shooting for modern C++, why not use Botan rather than OpenSSL?

[https://botan.randombit.net/](https://botan.randombit.net/)

------
rankam
What is the use case for a C++ web framework? Would higher level
languages/frameworks make use of this to do some of the heavy lifting? Would a
company migrate to something like this once at scale? Or, are there just some
people/companies who prefer to use C++?

~~~
VikingCoder
If you're writing a C++ application, it can be quite useful. I've shared this
before:

I worked at a company once that had a really decent HTTP server library...
That they put in every program.

You'd launch an app, and to debug it, you'd access
[http://localhost:9001](http://localhost:9001). From there, you could go to
URLs for different libraries in the app. Like, if you had a compression
library, you could go
[http://localhost:9001/compression](http://localhost:9001/compression). It
would show stats about the recent work it had done, how long it took, how much
CPU, RAM, disk it used. The state of variables now, etc. You could click a
button to get it to dump its cache, etc.

If you were running a service on a remote machine, accessing it over HTTP to
control it was just awesome.
[http://r2d2:9001/restart](http://r2d2:9001/restart).
[http://r2d2:9001/quit](http://r2d2:9001/quit).
[http://r2d2:9001/logfile](http://r2d2:9001/logfile).

Oh, and the services running on that remote machine would register with a
system-level monitor. So, if you went to
[http://r2d2/services](http://r2d2/services), you could see a list of links to
connect to all of the running services.

...and every service registered with a global monitor for that service. So, if
you knew a Potato process was running somewhere, but you weren't sure which
machine it was on, you could find it by going to
[http://globalmonitor/Potato](http://globalmonitor/Potato), and you'd see a
list of machines it was running on.

Just all kinds of awesomeness were possible. Can not recommend enough.

And, I mean like, programs with a GUI. Like, picture a game. Except on my
second monitor, I had Chrome open, talking to the game's engine. I could use
things like WebSockets to stream data to the browser. Like, every time the
game engine rendered a shot, I could update it (VNC-style) in the browser
window. Except annotated with stats, etc. It was just the most useful way to
organize different debug information.

And what was great was that writing a library, and wanting to output
information, you wouldn't write it to std out... You'd make HTML content, and
write to it. Want to update it? Clear the buffer and write to it again. As a
user, if you ever want to read the buffer, you just browse it. Want to update
it? Refresh the window. Or better yet, stream it over a websocket. Like Std
Out on steroids. If you need to combine the output from a few libraries in a
new window, you just write a bit more HTML in your code, and you're doin' it.

It's just another example, in my mind, of the power of libraries. We all get
used to thinking of frameworks (IIS, Apache) as the only way to solve a
problem, that we forget to even think about putting things together in new and
unexpected ways. HTTP as a library - HELL YES.

Using HTML to debug programs, live, is highly under-utilized.

~~~
CyberDildonics
I would say that debugging a program live is highly underrated. There is no
inherent reason why building a webserver into everything and using html for
visualization is the best way to go. Shared memory can be used and be 100-1000
times faster, which can make a huge difference if you want to visualize large
amounts of data like point clouds, pixels, etc. as they change.

In your scenario it sounds like an easy way to make a big step forward, though
I don't think that takes it far enough.

~~~
VikingCoder
Well, for one thing, you're presuming the person who wants to inspect
something a) has a debugger, b) knows how to use it, c) that the machine
running the application allows access through those ports.

~~~
CyberDildonics
I didn't presume any of those things and I'm not sure where any of those ideas
come from. A program can write to shared memory that is read by a separate
program. That doesn't take a debugger and it doesn't take 'ports'. I'm
actually not sure what you mean by ports.

~~~
VikingCoder
Sorry, I feel like we're really mis-communicating.

I proposed an idea, and you proceeded to tell me "There is no inherent reason
why [my idea] is the best way to go." I think that's a pretty rough way to
respond to someone suggesting an idea that might be useful under some
circumstances. It's a possibly new tool in your tool-belt. I didn't mean to
suggest that a hammer "is the best way to go" for any job. But sometimes the
problem is a nail, and a hammer is the best tool.

You highlighted the value of "debugging a program live," which is true, but I
thought you meant using a sophisticated debugger (gdb / Visual Studio, etc).
For instance, Microsoft Visual Studio has (or used to have) the ability to
have plug-ins to help you visualize complex structures in memory of the
running process, for instance showing a Bitmap as an actual image on your
screen. I thought that's what you meant, or just using gdb or some other
sophisticated debugger. But yes, that was my misunderstanding.

Shared memory is nice, and I've used it before, but it required me to store
all of my interesting objects in shared memory structures. Which meant
changing how my application was written. Yes, sometimes I could see that being
amazing. Or I suppose you make a large copy of them.

I've also done the trick where, if I hit a URL on my app, then it took the
point clouds, pixels, etc, and provided a rendered PNG image of them. But it
could do it without requiring me to restructure my program's memory layout
(other than a few multi-threading locks, when needed.) And I've done that over
WebSockets, with interactive rendering rates, basically like a VNC. And what
was nice about that, again, was that I could run a process on one machine, and
debug it (through HTML) from another. And grant that ability to other users,
without having to tell them how to install a debugger app, and giving that app
access to connect over the network, and etc.

The ports thing was in reference to the ability of Microsoft Visual Studio
(and presumably other debuggers) to do remote debugging, attaching themselves
to a process running on another computer. So, you have to be able to connect
to that process. Whereas my proposal could work on normal HTTP / HTTPS ports,
and with authentication, could enable a user to access debug views.

Anyway, yes, I very much agree with you that debugging a program live is
highly underrated, and I think it's good if people share different ways to do
that.

------
rolodato
Drogon is similar to "drogón" in Spanish, which means "junkie" or someone who
takes a lot of drugs.

~~~
aaomidi
I guess if we're doing random tidbits.

And "junkie" is a very harmful term to use and implies a moral failing of the
drug user.

------
sardar0
Developing a trust accounting application for law firms in Drogon. It's an
excellent framework written in Modern C++. Very easy to work with. Check out
the Source code on git, it is beautifully written. If you are proficient in
Modern C++, then this is the framework to use for speedy development. Just as
an aside, I migrated the project from Go to C++.

~~~
continuations
> I migrated the project from Go to C++

Any particular reasons why?

------
hu3
I knew that name was familiar. Drogon scores nicely in Techempower's
benchmarks:

[https://www.techempower.com/benchmarks/#section=data-r19&hw=...](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=plaintext)

~~~
dragonsh
Yes indeed it is one of the top performers. But I feel need more real-life
examples of companies and systems using it.

Hope it generates some interest among programming community to also look at
modern C++ as viable web development platform.

~~~
saberience
The problem isn't performance, the problem is developer productivity. C++
isn't known for building things quickly. Why would anyone use this over DotNet
Core, which is also highly performance but significantly easier to understand.
Also building anything in a complex language like C++ means more bugs and
errors.

~~~
CyberDildonics
I don't find this to be true at all with modern C++. Doing the same things
ends being more straightforward in my experience. Setting up compilation is
often more painful and sooner or later I run into some snags with const and
map iteration, though those don't end up being long term time sinks.

------
jason0597
I was looking for a C++ HTTP framework a couple of months ago for a hobby
project of mine. However, the whole debacle with WinGet and AppGet really left
a very horrible taste in my mouth, that I did not want anything to do with a
framework built by Microsoft. So I opted for Boost::Beast

------
scott_s
edit: I am wrong, see comment below.

Since this project was submitted by project creator, it deserves "Show HN"
status
([https://news.ycombinator.com/showhn.html](https://news.ycombinator.com/showhn.html)).

~~~
dragonsh
I am not the creator, just stumbled on it looking for examples in modern C++,
was especially looking for C++ 20. Found it interesting and try to share on
HN.

~~~
brighton36
I'm not sure if this is interesting to anyone. But, I wanted something a bit
more lightweight, so, I'm writing my own kinda/sorta Drogon thing. It's using
git and cmake to (hopefully) serve as a better library management system.
Here's the 'app' I'm devoloping:
[https://github.com/brighton36/vuecrudd](https://github.com/brighton36/vuecrudd)
and here's the project itself:
[https://github.com/brighton36/prails](https://github.com/brighton36/prails)

------
DrBazza
Unless I missed something, it says it can auto generate code, but I don't see
anything regarding Swagger/OpenAPI

~~~
hermanradtke
I think it means code generation using drogon_ctl.

