Skip to content

Garcia6l20/g6-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An unifex-based web framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published