Show HN: Open-source Express-like HTTP server in C++ (amsozzer.com)
Hey guys, I made an open-source Express like non blocking HTTP Server library in C++. Starting a new web server is as simple as initiating the app with the desired port (8080 default) and start registering routes.
#include <PlusWeb/HttpServer.h>
int main() { HttpServer app(3000);
app.GET("/users/:id", [](HttpRequest& req, HttpResponse& res) {
res.status(200).send(nlohmann::json{
{"id", req.params["id"]},
{"name", "ada"},
});
});
app.serve([] { std::cout << "listening on :3000\n"; });
}It supports middleware chaining and since it uses tries for storing routes instead of a flat array like Express, the performance gets better as the application scales up
For example: At 5 Routes PlusWeb is 4.8x faster than express whereas at 10,000 routes it is 253x faster than express
Playground: https://amsozzer.com/projects/plusweb It is available to use on https://github.com/Amsozzer1/PlusWeb
Some more profiling info available on https://github.com/Amsozzer1/PlusWeb/blob/main/PROFILING_REP...
Learn more about my mistakes building PlusWeb and how I fixed them on https://amsozzer.com/writing/i-could-not-understand-express-...
0 comments
[ 0.35 ms ] story [ 9.5 ms ] threadNo comments yet.