A very very minimal micro web framework written in C++ (not usable in production, obv).
It is a very minimalistic micro-web framework similar to flask but in entirely in C++. It uses fork() to make child process to handle concurrent connections.
Motivation: Because it can be made.
cpp-webframework/
├─ LICENSE
├─ README.md
├─ TODO
├─ include/
│ ├─ constants.h
│ ├─ encode.h
│ ├─ inja/
│ │ └─ inja.hpp
│ ├─ logger.h
│ ├─ middleware.h
│ ├─ nlohmann/
│ │ ├─ json.hpp
│ │ └─ json_fwd.hpp
│ ├─ request.h
│ ├─ response.h
│ ├─ router.h
│ └─ server.h
├─ main.cpp
└─ src/
├─ logger.cpp
├─ middleware.cpp
├─ request.cpp
├─ response.cpp
├─ router.cpp
└─ server.cpp
It currently has mainly two dependencies:
- nlohmann/json - for interacting JSON data format
- inja - for templating
Thank you arthurafarias for his wonderful gist which helped in encoding/decoding URI components.
Make a server object and define your routes in main.cpp like this:
Server server;
// Basic route
server.route("GET", "/hello", [](Request& req, Response& res) {
res.setContentType(MIME_JSON);
json response = {
{"message", "Hello, World!"},
{"status", "success"}
};
res.json(response);
});Accessing https://localhost:8080/hello will give :
{"message":"Hello, World!","status":"success"}Then compile:
g++ main.cpp src/*.cpp -o webThen run the output binary:
./webCurrently this only supports static file serving and returning data via JSON (which makes it somewhat usable for making very basic APIs). It also supports serving html pages with contextual data with inja.
Add redirect functionality- Add support for file upload
- Add support for authentication methods (currently the authentication middleware doesn't work as expected)
- Choose a nice name for the repo
The code is released under MIT License. See LICENSE.