{"id":22123864,"url":"https://github.com/joexbayer/c-web-modules","last_synced_at":"2025-04-04T20:13:34.149Z","repository":{"id":263290443,"uuid":"885926990","full_name":"joexbayer/c-web-modules","owner":"joexbayer","description":"A modular web framework for C, inspired by kernel modules. Dynamically upload and compile C code at runtime to build REST APIs, WebSocket services, and more. Includes support for JSON (Jansson), SQLite, OpenSSL, and streaming large data efficiently.","archived":false,"fork":false,"pushed_at":"2024-12-20T15:19:28.000Z","size":358,"stargazers_count":198,"open_issues_count":10,"forks_count":7,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T19:11:25.770Z","etag":null,"topics":["c","development","engine","http","json","modules","rest-api","restful","server","web","webframework","websocket"],"latest_commit_sha":null,"homepage":"https://joexbayer.github.io/c-web-modules/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joexbayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T18:56:41.000Z","updated_at":"2025-03-13T20:55:34.000Z","dependencies_parsed_at":"2024-11-17T16:22:13.286Z","dependency_job_id":"9e47e886-5bdc-403e-b844-c8663d6b180e","html_url":"https://github.com/joexbayer/c-web-modules","commit_stats":null,"previous_names":["joexbayer/c-web-modules"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joexbayer%2Fc-web-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joexbayer%2Fc-web-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joexbayer%2Fc-web-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joexbayer%2Fc-web-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joexbayer","download_url":"https://codeload.github.com/joexbayer/c-web-modules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242680,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","development","engine","http","json","modules","rest-api","restful","server","web","webframework","websocket"],"created_at":"2024-12-01T15:40:04.189Z","updated_at":"2025-04-04T20:13:34.128Z","avatar_url":"https://github.com/joexbayer.png","language":"C","readme":"# c-web-modules: Modules for the Web  \n\n\u003e **Note:**  \n\u003e This project is currently a **proof of concept** and represents the **bare minimum viable product (MVP)**.  \n\u003e It is not designed for production use, and there may be bugs, limitations, or incomplete features.  \n\u003e Use at your own discretion.\n\nWelcome to **c-web-modules**, a modular and efficient approach to web development in C. Inspired by kernel modules and AWS Lambda, this project allows you to upload C code directly to the server, which compiles and deploys it at runtime. No precompilation is necessary, and the server can easily be upgraded to include more features or external libraries.\n\n## Documentation\n\nFor more detailed information, please refer to the [official documentation](https://joexbayer.github.io/c-web-modules/).\n\n## Addressing the Challenges of C for Web Development  \n\nC isn’t typically the go-to for web development, and there are valid reasons why. Here’s how **c-web-modules** tackles some of the common concerns:  \n\n1. **Slow Build Cycles**:  \n   Instead of recompiling the entire application, **c-web-modules** allows you to upload raw C code. The server compiles it on-the-fly, enabling rapid iteration and eliminating the need for restarts. This is as close to \"hot reloading\" as you can get with C.  \n\n2. **Speed vs. Practicality**:  \n   While raw computation speed might not always be critical for web apps, **c-web-modules** shines in scenarios where performance matters, like handling heavy data processing or real-time applications. Modules let you inject optimized performance-critical code where it’s needed.  \n\n3. **Manpower and Time-to-Market**:  \n   By automating common server tasks (e.g., routing, module integration, and shared resources like SQLite3), **c-web-modules** reduces boilerplate and accelerates development compared to starting from scratch. It's not as fast as scripting languages, but it's far from the manual grind of traditional C projects.  \n\n4. **Memory Management and Crashes**:  \n   Modules are isolated and dynamically managed, reducing the risk of crashing the entire server. While C still requires careful memory management, the modular approach lets you focus on smaller, manageable pieces of functionality rather than tackling a monolithic application.  \n\n5. **Pre-Made Solutions**:  \n   By supporting external libraries like SQLite3, OpenSSL, and Jansson out of the box, **c-web-modules** leverages existing solutions, allowing developers to skip reinventing the wheel and focus on their application's unique needs.  \n\nThis isn’t a silver bullet—it’s a proof of concept. But **c-web-modules** aims to bring C’s raw power into the web world in a more developer-friendly way.  \n\n---\n\n## Getting started\n\n\n## Example: Counter Module  \n\nHere’s a simple example of a module that keeps track of a counter and returns its value every time you visit `/counter`.\nSee more examples in the `example/` folder.\n\n[Websocket](example/websocket.c)\n\n[Chat application](example/chat.c)\n\n[JSON](example/json.c)\n\n[TODO App](example/todo.c)\n\nSQLite3 App (TODO)\n\n#### `counter.c`  \n```c\n#include \u003cstdio.h\u003e\n#include \u003ccweb.h\u003e\n\nstatic int counter = 0;\nstatic const char* template = \n    \"\u003chtml\u003e\\n\"\n    \"  \u003cbody\u003e\\n\"\n    \"    \u003ch1\u003eCounter: %d\u003c/h1\u003e\\n\"\n    \"  \u003c/body\u003e\\n\"\n    \"\u003c/html\u003e\\n\";\n\n/* Route: /counter - Method GET */\nstatic int index_route(struct http_request *req, struct http_response *res) {\n    snprintf(res-\u003ebody, HTTP_RESPONSE_SIZE, template, counter++);\n    res-\u003estatus = HTTP_200_OK;\n    return 0;\n}\n\n/* Define the routes for the module */\nexport module_t config = {\n    .name = \"counter\",\n    .author = \"cweb\",\n    .routes = {\n        {\"/counter\", \"GET\", index_route, NONE},\n    },\n    .size = 1,\n};\n```\n\n---\n\n## Why Use c-web-modules?  \n\n1. **Code Deployment**: Upload raw C code to the server for on-the-fly compilation and deployment.  \n2. **No Precompilation**: Simplify your workflow—focus on writing code, and let the server handle compilation.  \n3. **Dynamic Updates**: Add or replace functionality without downtime or recompiling the entire server.  \n4. **Performance**: Written in C, the server offers unmatched speed and efficiency.  \n5. **WebSocket Support**: Even when modules are updated, existing WebSocket connections remain alive.  \n6. **Built-In Features**: Includes a cross-module cache and scheduler for deferred tasks.\n7. **Regex in Paths**: Define routes using regular expressions for more flexible and powerful URL matching. \n\nCurrently supported external libraries:  \n- **OpenSSL**: Currently only for hashing, but later for secure communication.  \n- **SQLite3**: Shared by all modules for lightweight database needs.  \n- **Jansson**: For easy JSON parsing and manipulation.  \n\n---\n\n# Deployment  \n\nDeploying code to the server is simple and can be done in multiple ways, depending on your workflow.\n\n### 1. Basic Deployment with `curl`  \n\nAt its core, deploying code to the server involves sending a POST request with the C file attached. Here’s an example using `curl`:  \n\n`curl -X POST -F \"code=@path/to/yourcode.c\" http://localhost:8080/mgnt`\n\n### 2. Using the cweb script and .ini config\nThe script handles:  \n- Sending the file to the server using `curl`.  \n- Parsing responses for success or failure.  \n- Providing helpful logs and error messages.  \n\n#### Deploying Multiple Files with a Config File  \n`./cweb deploy path/to/yourcode.c`\n\nYou can deploy multiple modules in one go using a configuration file. By default, the script looks for a file named `routes.ini`.  \n\nExample `routes.ini` file:  \n```ini\nserver_url=http://localhost:8080/mgnt\n\n[modules]\nexample1.c\nexample2.c\n```\n\nWhen using the .ini files you run: `./cweb deploy`\n\n## Windows\n\nFor Windows there currently only is a very primitve deploy.bat script:\n\n```bash\n.\\deploy.bat file.c\n```\n\nThe server needs to be specified inside the .bat file, default is: http://localhost:8080/mgnt\n\n### Errors\n\nError messages are forwarded back to you over http.\n\n---\n\n# Build it yourself!\n\n\u003e **Note:**  \n\u003e  MacOS support is not guaranteed!\n\nThe project depends on:\n\n```bash\n# Debian\nsudo apt-get install libssl-dev\nsudo apt-get install libsqlite3-dev\nsudo apt-get install libjansson-dev\n\n# Arch\nsudo pacman -S openssl\nsudo pacman -S sqlite\nsudo pacman -S jansson\n\n# Bug with archlinux and fanitizser, ref: https://github.com/joexbayer/c-web-modules/issues/12\nsudo sysctl vm.mmap_rnd_bits=30\n\n\n# MacOS\nbrew install openssl@3\nbrew install sqlite\nbrew install jansson\n```\n\nRun make to compile and make run to start the server.\n\n```bash\nmake\nmake run\n```\n\n## Docker\n\n```bash\ndocker-compose up --build\n```\n\n# How is c-web-modules different from Apache Modules and ISAPI Extensions?\n\nUnlike Apache modules and ISAPI extensions, which are tightly integrated into the server and require configuration changes followed by a server restart or reload, **c-web-modules** offers runtime flexibility.\n\n**Key Differences:**\n- **Dynamic Deployment**:  \n  c-web-modules allows you to upload raw C code directly to the server, which compiles and integrates it into the running application without restarts. Neither Apache modules nor ISAPI extensions support this level of runtime modification.\n\n- **Module Isolation**:  \n  Each module in c-web-modules is independently managed, minimizing the risk of crashing the entire server.\n\n- **WebSocket Updates**:  \n  WebSocket handlers can be updated at runtime without breaking existing connections, a feature not typically available in Apache modules or ISAPI.\n\nThis makes **c-web-modules** suitable for rapid experimentation and modular design, especially in scenarios requiring frequent updates without disrupting service.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoexbayer%2Fc-web-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoexbayer%2Fc-web-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoexbayer%2Fc-web-modules/lists"}