TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24849 14
BEVE)

`glz::lazy_json` provides on-demand parsing with zero upfront work. Construction is O(1) — it just stores a pointer. Only the bytes you actually access get parsed.

std::string json = R"({"name":"John","age":30,"scores":[95,87,92]})";
auto result = glz::lazy_json(json);
if (result) {
auto& doc = *result;
auto name = doc["name"].get<std::string_view>(); // Only parses "name"
auto age = doc["age"].get<int64_t>(); // Only parses "age"
}

For random access into large arrays, you can build an index in O(n) and then get O(1) lookups:

auto users = doc["users"].index(); // O(n) one-time build
auto user500 = users[500]; // O(1) random access

You can also deserialize into structs directly from a lazy view:

User user{};
glz::read_json(user, doc["user"]);

# HTTP Server, REST, and WebSockets

Glaze now includes a full HTTP server with async ASIO backend, TLS support, and WebSocket connections.

# Basic server

glz::http_server server;

server.get("/hello", [](const glz::request& req, glz::response& res) {
res.body("Hello, World!");
});

server.bind("127.0.0.1", 8080).with_signals();
server.start();
server.wait_for_signal();

# Auto-generated REST endpoints using reflection

You can register C++ objects and Glaze will automatically generate REST endpoints from reflected methods:

struct UserService {
std::vector<User> getAllUsers() { return users; }
User getUserById(size_t id) { return users.at(id); }
User createUser(const User& user) { users.push_back(user); return users.back(); }
};

glz::registry<glz::opts{}, glz::REST> registry;
registry.on(userService);
server.mount("/api", registry.endpoints);

Method names are mapped to HTTP methods automatically — `get*()` becomes GET, `create*()` becomes POST, etc.

# WebSockets

auto ws_server = std::make_shared<glz::websocket_server>();

ws_server->on_message([](auto conn, std::string_view msg, glz::ws_opcode opcode) {
conn->send_text("Echo: " + std::string(msg));
});

server.websocket("/ws", ws_server);

https://redd.it/1rrq9e6
@r_cpp
Reddit From the cpp community on Reddit: Glaze 7.2 - C++26 Reflection | YAML, CBOR, MessagePack, TOML and more Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 7, 2026Full Meeting C++ 2026 program released https://meetingcpp.com/mcpp/schedule/#2026 https://…
  2. Oct 7, 2026Qt moc now can handle basic C++ modules (Qt 6.12) https://codereview.qt-project.org/c/qt/q…
  3. Oct 7, 2026New to c++ Hello everybody,im new to cpp,and want to learn it,i have some knowledge with C…
  4. Oct 7, 2026Optimizing the Compressed Log Pipeline: https://github.com/Tencent/BqLog/blob/main/docs/Ar…
  5. Oct 7, 2026BqLog 2.6.0: a C++ logging library running on 30M+ devices daily, benchmarked against quil…
  6. Oct 7, 2026BqLog 2.6.0: a C++ logging library running on 30M+ devices daily, benchmarked against quil…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →