C++ library for reading and writing XML and creating web, REST and SOAP servers
  • C++ 91.6%
  • CMake 8.4%
Find a file
Maarten L. Hekkelman b32ce4322b
All checks were successful
test on Debian / build (Release, g++, debian-latest) (push) Successful in 12m58s
test on FreeBSD / build (Release, c++, freebsd-latest) (push) Successful in -16h36m11s
Proper implementation of status_code
2026-08-10 14:02:36 +02:00
.forgejo/workflows Update license information 2026-07-27 16:35:55 +02:00
.github Update license information 2026-07-27 16:35:55 +02:00
cmake More doxygen comments 2026-08-09 13:17:58 +02:00
docs Fix documentation 2026-07-30 20:20:45 +02:00
examples Moved private headers into details directory 2026-08-09 14:20:08 +02:00
include/zeep Proper implementation of status_code 2026-08-10 14:02:36 +02:00
LICENSES Update license information 2026-07-27 16:35:55 +02:00
src Proper implementation of status_code 2026-08-10 14:02:36 +02:00
test Moved private headers into details directory 2026-08-09 14:20:08 +02:00
.clang-format Update license information 2026-07-27 16:35:55 +02:00
.clang-tidy Update license information 2026-07-27 16:35:55 +02:00
.gitignore Update license information 2026-07-27 16:35:55 +02:00
changelog.md Version bump and updated changelog 2026-08-09 14:25:24 +02:00
CMakeLists.txt Version bump and updated changelog 2026-08-09 14:25:24 +02:00
README.md Fix documentation 2026-07-30 20:20:45 +02:00

libzeep

DOI

github CI github CI

TL;DR

Libzeep is a web application framework written in C++. To see a starter project visit the libzeep-webapp-starter page.

About

Libzeep was originally developed to make it easy to create SOAP servers. And since working with SOAP means working with XML and no decent C++ XML library existed on my radar at that time I created a full XML library as well.

Unfortunately (well, considering the work I did), REST proved to be more popular than SOAP, and so I added a better JSON implementation to version 4 of libzeep as well as a way to create REST servers more easily.

But then I had to use Spring for some time and was impressed by the simplicity of building interactive web applications and thought I should bring that simplicity to the C++ world. After all, my applications need raw speed and no, Java is not fast.

Version 6.0.0 of libzeep was a completely refactored set of libraries. One for manipulating XML, one for handling JSON and one for building web applications.

But then I decided it would be better to have the xml code in a separate library and so version 7 now comes without an XML library but uses zeem instead.

What remains is a web application library. This one makes it very easy to build a HTTP server that serves HTML but also speaks REST and SOAP. The current implementation consists of a HTTP server class to which you can add controllers. Each controller has a path prefix and handles requests for some entries in this uri path. The base class zeep::http::controller can be used as a base class for a REST controller.

The HTML controller can be used as a base class so you can add methods that will be called for certain URI paths. In combination with the available tag processors you can then create and return dynamic XHTML pages.

Full documentation can be found here

Building libzeep

To build libzeep you have to have cmake installed.

And, unless you are using macOS, it is recommended to install mrc in order to have resources support in libzeep.

The commands to build libzeep from the command line are e.g.:

    git clone https://forge.hekkelman.net/maarten/zeep
    cd libzeep
    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
    cmake --build build
    ctest --test-dir build
    cmake --install build

Creating a simple web application

Create a template in xhtml first, store this as hello.xhtml in a directory called docroot:

<!DOCTYPE html SYSTEM "about:legacy-compat">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:z="http://www.hekkelman.com/libzeep/m2">
  <head>
    <title>Hello</title>
  </head>
  <p>Hello, <span z:text="${name ?: 'world'}"/>!</p>
</html>

Then create a source file called http-server.cpp with the following content:

#define WEBAPP_USES_RESOURCES 0

#include <zeep/http/server.hpp>
#include <zeep/http/html-controller.hpp>
#include <zeep/http/template-processor.hpp>

class hello_controller : public zeep::http::html_controller
{
  public:
    hello_controller()
    {
        map_get("", &hello_controller::handle_index, "name");
        map_get("index.html", &hello_controller::handle_index, "name");
        map_get("hello/{name}", &hello_controller::handle_index, "name");
    }

    zeep::http::reply handle_index(const zeep::http::scope& scope,
        std::optional<std::string> user)
    {
        zeep::http::scope sub(scope);
        sub.put("name", user.value_or("world"));

        return get_template_processor().create_reply_from_template("hello.xhtml", sub);
    }
};

int main()
{
    zeep::http::server srv(std::filesystem::canonical("docroot"));

    srv.add_controller(new hello_controller());

    srv.bind("::", 8080);
    srv.run(2);

    return 0;
}

Create a CMakeLists.txt file:

cmake_minimum_required(VERSION 3.16)

project(http-server LANGUAGES CXX)

set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(zeep REQUIRED)

add_executable(http-server http-server.cpp)
target_link_libraries(http-server zeep::zeep)

And configure and build the app:

cmake .
cmake --build .

And then run it:

./http-server

Now you can access the result using the following URL's: