All Projects → 0xdead4ead → Beasthttp

0xdead4ead / Beasthttp

Licence: bsd-2-clause
Provides helper tools for creating RESTful services using Boost.Beast

Programming Languages

cpp11
221 projects
cpp14
131 projects

Projects that are alternatives of or similar to Beasthttp

Simple Web Server
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
Stars: ✭ 2,261 (+896.04%)
Mutual labels:  server, asio, https
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+1327.75%)
Mutual labels:  boost, server, asio
Armor
Uncomplicated, modern HTTP server
Stars: ✭ 1,629 (+617.62%)
Mutual labels:  server, https
Boost Asio Study
Examples and toturials for C++ Boost Asio library.
Stars: ✭ 144 (-36.56%)
Mutual labels:  boost, asio
Mutual Tls Ssl
🔐 Tutorial of setting up Security for your API with one way authentication with TLS/SSL and mutual mutual authentication for a java based web server and a client with both Spring Boot. Different clients are provided such as Apache HttpClient, OkHttp, Spring RestTemplate, Spring WebFlux WebClient Jetty and Netty, the old and the new JDK HttpClient, the old and the new Jersey Client, Google HttpClient, Unirest, Retrofit, Feign, Methanol, vertx, Scala client Finagle, Featherbed, Dispatch Reboot, AsyncHttpClient, Sttp, Akka, Requests Scala, Http4s Blaze, Kotlin client Fuel, http4k, Kohttp and ktor. Also other server examples are available such as jersey with grizzly. Also gRPC examples are included
Stars: ✭ 163 (-28.19%)
Mutual labels:  server, https
Cpp Rotor
Event loop friendly C++ actor micro-framework
Stars: ✭ 111 (-51.1%)
Mutual labels:  boost, asio
Cpp Bredis
Boost::ASIO low-level redis client (connector)
Stars: ✭ 117 (-48.46%)
Mutual labels:  boost, asio
Lear
Linux Engine for Asset Retrieval - speed-profiled C HTTP server
Stars: ✭ 165 (-27.31%)
Mutual labels:  server, https
Go Bootstrap
Easy way to bootstrap a web server in Go (Routing|Middleware|Https)
Stars: ✭ 27 (-88.11%)
Mutual labels:  server, https
Asio samples
Examples (code samples) describing the construction of active objects on the top of Boost.Asio. A code-based guide for client/server creation with usage of active object pattern by means of Boost C++ Libraries.
Stars: ✭ 191 (-15.86%)
Mutual labels:  boost, asio
Actionhero
Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks
Stars: ✭ 2,280 (+904.41%)
Mutual labels:  server, https
Tcpbin
Very crude and poorly written HTTP(s) and SMTP bin
Stars: ✭ 85 (-62.56%)
Mutual labels:  server, https
Zinc
Zinc HTTP Components is an open-source Smalltalk framework to deal with the HTTP networking protocol.
Stars: ✭ 60 (-73.57%)
Mutual labels:  server, https
Watsonwebserver
Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
Stars: ✭ 125 (-44.93%)
Mutual labels:  server, https
Gaia
C++ framework for rapid server development
Stars: ✭ 58 (-74.45%)
Mutual labels:  server, asio
Httpp
Micro http server and client written in C++
Stars: ✭ 144 (-36.56%)
Mutual labels:  boost, https
Evmongoose
DEPRECATED. Evmongoose is an asynchronous, event(libev) based multi-protocol embedded networking library with functions including TCP, HTTP, WebSocket, MQTT and much more. It's based on mongoose and libev implementation and it's support Lua API.
Stars: ✭ 199 (-12.33%)
Mutual labels:  server, https
Simple Websocket Server
A very simple, fast, multithreaded, platform independent WebSocket (WS) and WebSocket Secure (WSS) server and client library implemented using C++11, Boost.Asio and OpenSSL. Created to be an easy way to make WebSocket endpoints in C++.
Stars: ✭ 685 (+201.76%)
Mutual labels:  server, asio
Restinio
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use
Stars: ✭ 694 (+205.73%)
Mutual labels:  asio, https
Webcc
Lightweight C++ HTTP client and server library based on Asio for embedding purpose.
Stars: ✭ 167 (-26.43%)
Mutual labels:  boost, asio

SYNOPSIS license build badge.cpp

Easy HTTP (Header-only) library implemented using minimum C++11 and Boost.Beast. Allows you to get or provide REST resources available from an application in C ++. Use all the features of the Boost.Beast when constructing queries and answers.

FEATURES

  • HTTP 1.0 / 1.1
  • TLS/SSL
  • Pipeline request
  • Used I/O multiplexing model (Asio library implementation)
  • Timer manage (default action: Closing connection)
  • Server-Sent Events
  • Simple way to dynamic add REST resources using regex for path, and anonymous functions
  • Support accepted plain and SSL session on the same port

DEPENDENCIES

USAGE

More examples is here... The following notes show the standard syntax for setting up routes and starting a server!

Alias's represent instances of default classes for reactive (select/epool) design.

    using namespace _0xdead4ead;
    namespace beast = boost::beast;

    using http_session = http::reactor::_default::session_type;
    using http_listener = http::reactor::_default::listener_type;

Creating a new callback functions storage and route path for GET request with "/" resource:

    static const std::regex::flag_type regex_flags = std::regex::ECMAScript;

    http::basic_router<http_session> router{regex_flags};

    router.get("^/$", [](auto beast_http_request, auto context) {
        context.send(make_200<beast::http::string_body>(beast_http_request, "Main page\n", "text/html"));
    });

    router.all("^.*$", [](auto beast_http_request, auto context) {
        context.send(make_404<beast::http::string_body>(beast_http_request, "Resource is not found\n", "text/html"));
    });

    // or so ...

    using http::literals::operator""_get;

    "^/$"_get.advance(router, [](auto beast_http_request, auto context) {
        // as above...
    });

    "^.*$"_all.advance(router, [](auto beast_http_request, auto context) {
        // as above...
    });

It is possible to add multiple handlers for one route. For movement on them std::next or std::advance is used:

    router.get("^/a/b$",
       [](auto /*beast_http_request*/, auto /*context*/, auto iterator){
        // process /a
        std::next(iterator)();
    }, [](auto /*beast_http_request*/, auto /*context*/){
        // process /b
    });

Getting a parameter from a URI. Request send example curl localhost --request 'GET' --request-target '/user/param?y=1992':

    using pack = http::param::pack<int>;

    router.param<pack>().get("^/user/param[?]y=(\\d+)$",
       [](auto /*beast_http_request*/, auto /*context*/, auto args){
        assert(std::get<0>(args) == 1992);
    });

    // or

    router.param<pack>().get("^/user/param[?]y=(\\d+)$",
       [](auto /*beast_http_request*/, auto /*context*/, auto iterator, auto /*args*/){
        // process /user
        std::next(iterator)();
    }, [](auto /*beast_http_request*/, auto /*context*/, auto args){
        // process /param
        assert(std::get<0>(args) == 1992);
    });

Getting a parameter using a string literal (as above) :

    // For value f'n is required c++14
    using http::literals::value;
    using http::literals::operator""_c;

    auto param = router.param<pack>();

    "^/user/param[?]y=(\\d+)$"_get.advance(std::move(param),
       [](auto /*beast_http_request*/, auto /*context*/, auto args){
        assert(value(args, 0_c) == 1992);
    });

Create modular, mounted route handlers:

    http::basic_router<http_session> animals{regex_flags};

    animals.get("^/cat$", [](auto beast_http_request, auto context){ // '/animals/cat'
        context.send(make_200<beast::http::string_body>(beast_http_request, "me-ow\n", "text/html"));
    });

    animals.get("^/dog$", [](auto beast_http_request, auto context){ // '/animals/dog'
        context.send(make_200<beast::http::string_body>(beast_http_request, "aw! aw! Rrrrr\n", "text/html"));
    });

    animals.get("^/mouse$", [](auto beast_http_request, auto context){ // '/animals/mouse'
        context.send(make_200<beast::http::string_body>(beast_http_request, "...\n", "text/html"));
    });

    animals.get("^[/]??$", [](auto beast_http_request, auto context){ // '/animals' or '/animals/'
        context.send(make_200<beast::http::string_body>(beast_http_request, "animals home page\n", "text/html"));
    });

    router.use("^/animals$", animals);

Create handlers routes, forming a chain, for the route path:

    http::chain_router<http_session> books{regex_flags};

    books.route("^/book$")
            .get([](auto beast_http_request, auto context) {
        context.send(make_200<beast::http::string_body>(beast_http_request, "get a random book\n", "text/html"));
    })
            .post([](auto beast_http_request, auto context) {
        context.send(make_200<beast::http::string_body>(beast_http_request, "add a book\n", "text/html"));
    })
            .put([](auto beast_http_request, auto context) {
        context.send(make_200<beast::http::string_body>(beast_http_request, "update the book\n", "text/html"));
    });

    router.use("^/books$", books);

Start listening on 0.0.0.0:8080

    // global namespace
    static boost::asio::io_context ioc;
    static boost::asio::posix::stream_descriptor out{ioc, ::dup(STDERR_FILENO)};
    //

    const auto& onError = [](auto system_error_code, auto from){
        http::out::pushn<std::ostream>(
                    out, "From:", from, "Info:", system_error_code.message());
    };

    const auto& onAccept = [&](auto asio_socket){
        auto endpoint = asio_socket.remote_endpoint();

        http::out::prefix::version::time::pushn<std::ostream>(
                    out, endpoint.address().to_string() + ':' + std::to_string(endpoint.port()), "connected!");

        http_session::recv(std::move(asio_socket), router, onError);
    };

    auto const address = boost::asio::ip::address_v4::any();
    auto const port = static_cast<unsigned short>(8080);

    http_listener::launch(ioc, {address, port}, onAccept, onError);

Run the I/O service on the requested number of threads:

    std::thread t{[](){
        ioc.run();
    }};

    // do other work...

    t.join();

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].