All Projects → Tectu → malloy

Tectu / malloy

Licence: MIT license
A C++ library providing embeddable server & client components for both HTTP and WebSocket.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to malloy

BCA-Phantom
A multi-platform HTTP(S) Reverse Shell Server and Client in Python 3
Stars: ✭ 80 (+175.86%)
Mutual labels:  http-client, http-server, network-programming
Httpp
Micro http server and client written in C++
Stars: ✭ 144 (+396.55%)
Mutual labels:  boost, http-client, http-server
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+11075.86%)
Mutual labels:  boost, http-client, http-server
foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 61 (+110.34%)
Mutual labels:  http-client, beast, http-server
go-sse
Fully featured, spec-compliant HTML5 server-sent events library
Stars: ✭ 165 (+468.97%)
Mutual labels:  http-client, http-server
hunt-http
http library for D, support http 1.1 / http 2.0 (http2) / websocket server and client.
Stars: ✭ 29 (+0%)
Mutual labels:  http-client, http-server
Shareaza
Shareaza is a peer-to-peer client for Windows that allows you to download any file-type found on several popular P2P networks.
Stars: ✭ 103 (+255.17%)
Mutual labels:  boost, http-client
zenith
⚡ Functional Scala HTTP server, client, and toolkit.
Stars: ✭ 15 (-48.28%)
Mutual labels:  http-client, http-server
http4ts
Server as a Function http toolkit for TypeScript & JavaScript
Stars: ✭ 30 (+3.45%)
Mutual labels:  http-client, http-server
Simple-Log
dnkpp.github.io/Simple-Log/
Stars: ✭ 13 (-55.17%)
Mutual labels:  cpp20, cpp20-library
waspy
WASP framework for Python
Stars: ✭ 43 (+48.28%)
Mutual labels:  http-client, http-server
BinaryLove3
Simple C++ 20 Serialization Library that works out of the box with aggregate types!
Stars: ✭ 13 (-55.17%)
Mutual labels:  cpp20, cpp20-library
EthernetWebServer SSL
Simple TLS/SSL Ethernet WebServer, HTTP Client and WebSocket Client library for for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. It now supports Ethernet TLS/SSL Client. The library supports …
Stars: ✭ 40 (+37.93%)
Mutual labels:  http-client, http-server
cpphttpstack
c++ api for http client & server
Stars: ✭ 30 (+3.45%)
Mutual labels:  http-client, http-server
matador
Take your appclication by the horns
Stars: ✭ 59 (+103.45%)
Mutual labels:  http-client, http-server
Avhttp
avhttp is concurrent http downloader
Stars: ✭ 232 (+700%)
Mutual labels:  boost, http-client
fancy
High performance web server
Stars: ✭ 20 (-31.03%)
Mutual labels:  http-server, network-programming
boost beast websocket echo
A collection of Demo applications to try to help you understand how Asio and Beast work
Stars: ✭ 12 (-58.62%)
Mutual labels:  boost, beast
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (+258.62%)
Mutual labels:  cpp20, cpp20-library
rawhttp
HTTP library to make it easy to deal with raw HTTP.
Stars: ✭ 156 (+437.93%)
Mutual labels:  http-client, http-server

Overview

Malloy is a small, embeddable HTTP & WebSocket server & client built on top of boost.beast.

The main use case for this library is a C++ project which needs to embedd an HTTP and/or WebSocket server and/or client.

Features

The following list provides an overview of the currently implemented features. Some of these are optional and can be enabled/disabled.

  • High-level controller to setup I/O context, SSL context, worker threads and more
  • HTTP
    • Plain or TLS (SSL) connections
    • Cookies
    • Sessions
    • Upgrading connections to WebSocket
    • Client
      • Response filters
    • Server
      • Routing
        • Simple handlers (useful for building REST APIs)
          • Target matching via regex
          • Capturing groups via regex
        • Sub-routers (nested/chained routers)
        • Redirections
        • File serving locations
          • Optional cache-control directives
        • Preflight responses
        • Access policies
          • HTTP basic auth
          • Custom access policies
        • Websocket endpoints (with auto-upgrade from HTTP)
      • Request filters
  • WebSocket
    • Client
    • Server
    • Connections upgradable from HTTP
  • HTML
    • Forms
      • Supported encoding types
        • application/x-www-form-urlencoded
        • multipart/form-data
        • text/plain
      • Parsing
      • Rendering

Licensing

This library is MIT licensed. Dependencies ship with their own licensing models.

Requirements

Building (and using) this library requires:

  • A C++20 capable compiler
    • GCC >= 10.3 (MinGW works!)
    • Clang >= 13
    • MSVC >= 19.29 (VS 2019)
  • CMake 3.17 or newer

As of today, this library was tested successfully on:

  • Windows 10 (with both MSVC and MinGW)
  • Linux (Ubuntu, Debian, Fedora, ...)
  • FreeBSD

Dependencies

Required:

  • Boost 1.74.0 or newer
  • spdlog 1.8.3 or newer
  • fmt 7.1.3 or newer (must be compatible with spdlog version)

Optional:

Examples

A variety of examples can be found in the /examples directory. You should definitely check those out! What follows are snippets for a simple HTTP server and a simple HTTP client.

HTTP Server:

int main()
{
    // Create malloy controller config
    malloy::server::routing_context::config cfg;
    cfg.interface   = "127.0.0.1";
    cfg.port        = 8080;
    cfg.doc_root    = "/path/to/http/docs"
    cfg.num_threads = 5;
    cfg.logger      = std::make_shared<spdlog::logger>();

    // Create malloy controller
    malloy::server::routing_context c{cfg};

    // Create the router
    auto& router = c.router();
    {
        using namespace malloy::http;

        // A simple GET route handler
        router.add(method::get, "/", [](const auto& req) {
            response res{status::ok};
            res.body() = "<html><body><h1>Hello World!</h1><p>some content...</p></body></html>";
            return res;
        });

        // Add a route to an existing file
        router.add(method::get, "/file", [](const auto& req) {
            return generator::file(examples_doc_root, "index.html");
        });

        // Add a route to a non-existing file
        router.add(method::get, "/file_nonexist", [](const auto& req) {
            return generator::file(examples_doc_root, "/some_nonexisting_file.xzy");
        });

        // Add some redirections
        router.add_redirect(status::permanent_redirect, "/redirect1", "/");
        router.add_redirect(status::temporary_redirect, "/redirect2", "/");

        // Add some file serving
        router.add_file_serving("/files", examples_doc_root);

        // Add a websocket echo endpoint
        router.add_websocket("/echo", [](const auto& req, auto writer) {
            std::make_shared<malloy::examples::ws::server_echo>(writer)->run(req);
        });
    }

    // Start
    start(std::move(c)).run();

    return EXIT_SUCCESS;
}

HTTP client:

int main()
{
    // Create the controller config
    malloy::client::controller::config cfg;
    cfg.num_threads = 1;
    cfg.logger      = create_example_logger();

    // Create the controller
    malloy::client::controller c{cfg};

    // Start
    [[maybe_unused]] auto session = start(c);

    // Create HTTP request
    malloy::http::request req(
        malloy::http::method::get,
        "www.google.com",
        80,
        "/"
    );
    
    // Make HTTP request
    auto stop_token = c.http_request(req, [](auto&& resp) mutable {
        std::cout << resp << std::endl;
    });
    const auto ec = stop_token.get();
    if (ec) {
        spdlog::error(ec.message());
        return EXIT_FAILURE;
    }


    return EXIT_SUCCESS;
}

Motivation

This started off with the intention of creating a more complex, real-world example of how to use boost.beast.

Security

This is a work in progress and should generally be perceived as unfit for any production use.

As of today, no security research has been performed on this library.

Malloy is an open-source library provided WITHOUT any WARRANTY or GUARANTEE regarding security, safety, functionality or anything else. Use at your own risk!

Documentation

Available documentation sources:

  • API documentation (doxygen)

Doxygen

The Doxygen API documentation can be generated with little hassle:

doxygen ./Doxyfile

The generated output(s) may be found under /docs/doxygen. Simply open /docs/doxygen/html/index.html in the web browser of your choosing.

Integration

Malloy is designed to be an embeddable component for other C++ applications. The easiest way to integrate Malloy is via CMake's FetchContent() infrastructure:

FetchContent_Declare(
    malloy
    GIT_REPOSITORY https://github.com/tectu/malloy
    GIT_TAG        main
)
FetchContent_MakeAvailable(malloy)

If you like to modify set some of Malloy's CMake variables, the FetchContent_MakeAvailable() call can be replaced accordingly:

FetchContent_Declare(
    malloy
    GIT_REPOSITORY https://github.com/tectu/malloy
    GIT_TAG        main
)
FetchContent_GetProperties(malloy)
if(NOT malloy_POPULATED)
    FetchContent_Populate(malloy)
    
    # Change various malloy cmake options
    set(MALLOY_BUILD_EXAMPLES OFF CACHE INTERNAL "")
    set(MALLOY_BUILD_TESTS OFF CACHE INTERNAL "")
    set(MALLOY_BUILD_SHARED ON CACHE INTERNAL "")
    set(MALLOY_FEATURE_CLIENT OFF CACHE INTERNAL "")
    set(MALLOY_FEATURE_SERVER ON CACHE INTERNAL "")
    set(MALLOY_FEATURE_TLS ON CACHE INTERNAL "")
    set(MALLOY_FEATURE_APPFW ON CACHE INTERNAL "")
    
    add_subdirectory(${malloy_SOURCE_DIR} ${malloy_BINARY_DIR})
endif()

You may replace GIT_TAG with a commit hash or a release tag such as 1.0.0.

After fetching the content, it's only a matter of linking the malloy library target(s) to the consuming application:

target_link_libraries(
    my_application
    PRIVATE
        malloy-server       # Link malloy's server components
        malloy-client       # Link malloy's client components
)

Where my_application is your application (or library) target that should consume malloy.

Options

Various cmake options are available to control the build:

Build

Option Default Description
MALLOY_BUILD_EXAMPLES ON Whether to build examples.
MALLOY_BUILD_TESTS ON Whether to build the test suite(s).
MALLOY_BUILD_SHARED OFF Whether to build shared libraries. If set to OFF, static libraries will be built.

Features

Option Default Description
MALLOY_FEATURE_CLIENT ON Enable client features.
MALLOY_FEATURE_SERVER ON Enable server features.
MALLOY_FEATURE_HTML ON Whether to enable HTML support.
MALLOY_FEATURE_TLS OFF Whether to enable TLS support.
MALLOY_FEATURE_APPFW OFF Whether to enable the server-side application framework components.

Dependencies

Option Default Description
MALLOY_DEPENDENCY_SPDLOG_DOWNLOAD ON Whether to use FetchContent() to pull in spdlog. If set to OFF, find_package() is used instead.
MALLOY_DEPENDENCY_FMT_DOWNLOAD ON Same as above but for fmt
MALLOY_DEPENDENCY_JSON_DOWNLOAD ON Same as above but for nlohmann/json
MALLOY_DEPENDENCY_INJA_DOWNLOAD ON Same as above but for pantor/inja
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].