Skip to content

Latest commit

 

History

History
67 lines (54 loc) · 1.7 KB

README.md

File metadata and controls

67 lines (54 loc) · 1.7 KB

g6 web library

An unifex-based web framework

Simple server example

auto server = 
  make_server(ctx,
              web::proto::http,
              *net::ip_endpoint::from_string("127.0.0.1:4242"))
co_await async_serve(
  server, server_stop_source.get_token(),
  [&]<typename Session>(Session &session) {
    return [&session](auto request) -> task<void> {
      while (net::has_pending_data(request)) {
        auto body = co_await net::async_recv(request);
        spdlog::info("body: {}", std::string_view{
            reinterpret_cast<char *>(body.data()), body.size()});
      }
      co_await net::async_send(session, http::status::ok, as_bytes(span{"OK !", 4}));
    };
  );

Simple client example

auto session =
    co_await net::async_connect(ctx, web::proto::http,
                                *net::ip_endpoint::from_string("127.0.0.1:4242"));
auto response = co_await net::async_send(
    session, "/", http::method::post, as_bytes(span{"Hello !", 7}));

std::string body_str;
while (net::has_pending_data(response)) {
  auto body = co_await net::async_recv(response);
  body_str += std::string_view{reinterpret_cast<char *>(body.data()),
                               body.size()};
}
spdlog::info("body: {}", body_str);

More complex examples:

Build

mkdir build && cd build
conan install .. --build=missing
cmake ..
cmake --build

Features

  • HTTP 1.1 server
  • HTTP 1.1 client
  • HTTP router
  • Chunked transfers (server download)
  • Chunked transfers (client upload)
  • Websocket server
  • Websocket client