DevTrends开发者趋势
主题色

c4punks /

cwist

First of all, I'm not claiming that my framework will save industrial C/C++ development. It's just a hobby project. Industrial code needs safer code, not easier code. But when you're developing a blog…

DT数据与运维DT生活与娱乐DT内容 / 资源DT库 / SDKDTWeb

关于

First of all, I&#x27;m not claiming that my framework will save industrial C&#x2F;C++ development. It&#x27;s just a hobby project. Industrial code needs safer code, not easier code. But when you&#x27;re developing a blog at 8 PM, long template errors are annoying. You need CRUD and RDBMS. It&#x27;s simple. CWIST is for that kind of work. It sacrifices memory safety, smart pointers, and modern C++ abstractions. In return, compile errors are more predictable. #include <stdio.h> #include <cwist&#x2F;app.h> #include <cwist&#x2F;core&#x2F;db&#x2F;pool.h> #include <cwist&#x2F;core&#x2F;template&#x2F;template.h> static cwist_db_pool_t *g_db_pool; static void send_error(cwist_http_response *res, const char *msg) { res->status_code = CWIST_HTTP_INTERNAL_ERROR; cwist_http_header_add(&res->headers, "Content-Type", "text&#x2F;plain"); cwist_sstring_assign(res->body, msg); } static void render(cwist_http_response *res, const char *path, cJSON *ctx) { cwist_sstring *html = cwist_template_render_file(path, ctx); if (html) { cwist_http_header_add(&res->headers, "Content-Type", "text&#x2F;html"); cwist_sstring_assign(res->body, html->data); cwist_sstring_destroy(html); } cJSON_Delete(ctx); } static void handle_index(cwist_http_request *req, cwist_http_response *res) { (void)req; cJSON *ctx = cJSON_CreateObject(); cJSON_AddStringToObject(ctx, "title", "CWIST Example"); cJSON_AddStringToObject(ctx, "greeting", "Hello from CWIST"); render(res, "templates&#x2F;index.html", ctx); } static void handle_users(cwist_http_request *req, cwist_http_response *res) { (void)req; if (!g_db_pool) return send_error(res, "database pool unavailable"); cwist_db_pool_exec(g_db_pool, "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);" "INSERT INTO users (name) SELECT &#x27;Alice&#x27; WHERE NOT EXISTS " "(SELECT 1 FROM users WHERE name = &#x27;Alice&#x27;);" "INSERT INTO users (name) SELECT &#x27;Bob&#x27; WHERE NOT EXISTS " "(SELECT 1 FROM users WHERE name = &#x27;Bob&#x27;);"); cJSON *rows = NULL; if (cwist_db_pool_query(g_db_pool, "SELECT id, name FROM users ORDER BY id;", &rows).error.err_i16) return send_error(res, "failed to query database"); cJSON *ctx = cJSON_CreateObject(); cJSON_AddItemToObject(ctx, "users", rows ? rows : cJSON_CreateArray()); render(res, "templates&#x2F;users.html", ctx); } static void handle_health(cwist_http_request *req, cwist_http_response *res) { (void)req; cwist_http_header_add(&res->headers, "Content-Type", "text&#x2F;plain"); cwist_sstring_assign(res->body, "ok"); } int main(void) { g_db_pool = cwist_db_pool_create(".&#x2F;app.db", 1); if (!g_db_pool) return 1; cwist_app *app = cwist_app_create(); cwist_app_get(app, "&#x2F;", handle_index); cwist_app_get(app, "&#x2F;users", handle_users); cwist_app_get(app, "&#x2F;health", handle_health); cwist_app_use_https(app, "cert.pem", "key.pem"); cwist_app_listen(app, 8082); cwist_app_destroy(app); cwist_db_pool_destroy(g_db_pool); return 0; } Code style is old and still small. The code is simple and stupid. CWIST functions use the same `cwist_xx_xx` naming format. It&#x27;s consistent. It&#x27;s harder to make a slop in CWIST. Features - CWIST GC for fast prototyping. It&#x27;s closer to a garbage sweeper than a traditional GC, and lighter. - Dev blog engine - HTML Template Engine - WASM External benchmark: https:&#x2F;&#x2F;web-frameworks-benchmark.netlify.app&#x2F;compare?f=cwist... Latest results may be masked: https:&#x2F;&#x2F;github.com&#x2F;the-benchmarker&#x2F;web-frameworks&#x2F;issues&#x2F;977... Unofficial results (not reliable): https:&#x2F;&#x2F;github.com&#x2F;c4punks&#x2F;CWIST&#x2F;actions&#x2F;runs&#x2F;39000473564&#x2F;jo... Dev blog: https:&#x2F;&#x2F;oborona.zip Org: https:&#x2F;&#x2F;c4punks.github.io It doesn&#x27;t help my portfolio, but please star the project if you enjoyed it. Special thanks to https:&#x2F;&#x2F;github.com&#x2F;thegoodengineer for inviting organization members.

收录记录

  1. 阮一峰周刊·用户投稿

    2026年9月25日 · 1 次收录

  2. Show HN

    2026年10月17日 · 1 次收录

讨论这个产品