Pistache Documentation

repository·master·Indexed 26 days ago

https://github.com/pistacheio/pistache

Pistache is a modern HTTP and REST framework for C++ written in pure C++17, designed for building high-performance web services. It features an asynchronous, non-blocking model using Promises and provides type-safe HTTP header management. The framework is primarily designed for Linux and is currently in a pre-1.0 unstable state. It supports integration via Meson, CMake, GNU Autotools, and pkg-config, with optional support for SSL and content encodings like Brotli, Deflate, and Zstd.

Tokens
5.9K
Snippets
26
Records
41
Agent score
86%

What's inside Pistache

  1. Understand Pistache project status and limitations

    master

    Pistache is currently pre-1.0 and is considered unstable. While much of the code is production-ready for developing RESTful APIs, users should be aware of the following:

    • HTTP Client: The HTTP client is currently buggy and may have issues.
    • Platform Support: Pistache is primarily designed for Linux. It uses platform-specific APIs where the standard library lacks alternatives. Support for other platforms is not yet official.
  2. Deploy the Pistache website to GitHub Pages

    master

    To build the website and push it to the gh-pages branch for GitHub Pages hosting, use the yarn deploy command. You must provide your GitHub username via the GIT_USER environment variable. If you are using SSH for deployment, set USE_SSH=true.

    GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
  3. Integrate Pistache using pkg-config in GNU Autotools

    master

    Include the following snippet in your configure.ac to check for libpistache and set the appropriate CXXFLAGS and LIBS.

    # Pistache...
    PKG_CHECK_MODULES(
        [libpistache], [libpistache >= 0.0.2], [],
        [AC_MSG_ERROR([libpistache >= 0.0.2 missing...])])
    YOURPROJECT_CXXFLAGS="$YOURPROJECT_CXXFLAGS $libpistache_CFLAGS"
    YOURPROJECT_LIBS="$YOURPROJECT_LIBS $libpistache_LIBS"
  4. Build Pistache from source on Linux

    master

    Clone the repository and use Meson to configure, compile, and install the project. You can enable features like SSL and various content encodings via Meson options.

    $ git clone https://github.com/pistacheio/pistache.git
    $ cd pistache
    $ meson setup build                                 \
        --buildtype=release                             \
        -DPISTACHE_USE_SSL=true                         \
        -DPISTACHE_BUILD_EXAMPLES=true                  \
        -DPISTACHE_BUILD_TESTS=true                     \
        -DPISTACHE_BUILD_DOCS=false                     \
        -DPISTACHE_USE_CONTENT_ENCODING_BROTLI=true     \
        -DPISTACHE_USE_CONTENT_ENCODING_DEFLATE=true    \
        -DPISTACHE_USE_CONTENT_ENCODING_ZSTD=true       \
        --prefix="$PWD/prefix"
    $ meson compile -C build
    $ meson install -C build
  5. Stream content using ResponseStream

    master

    For content where the length is unknown in advance, use chunked encoding via the ResponseStream class.

    Important: Headers must be configured on the ResponseWriter before calling .stream(), as headers become immutable once the stream starts.

    To use streaming:

    1. Configure headers on the response object.
    2. Call response.stream(Http::Code) to obtain a ResponseStream.
    3. Use the << operator to write chunks.
    4. Use the flush marker to push data without ending the stream.
    5. Use the ends marker to finalize the stream and send the final data.
  6. Integrate Pistache using pkg-config in CMake

    master

    Use the FindPkgConfig module to locate libpistache and link against the imported target.

    cmake_minimum_required(VERSION 3.6)
    project("MyPistacheProject")
    
    find_package(PkgConfig)
    pkg_check_modules(Pistache REQUIRED IMPORTED_TARGET libpistache)
    
    add_executable(${PROJECT_NAME} main.cpp)
    target_link_libraries(${PROJECT_NAME} PkgConfig::Pistache)
  7. Install Pistache via Ubuntu PPA (Unstable)

    master

    To use daily unstable snapshots of Pistache, add the unstable PPA and install libpistache-dev.

    $ sudo add-apt-repository ppa:pistache+team/unstable
    $ sudo apt update
    $ sudo apt install libpistache-dev