Note
THIS REPOSITORY IS NO LONGER MAINTAINED.
Based on how things have been going in my life, I'm unable to maintain this project plus I don't think I have the expertise to continue, I planned to use coroutines to avoid the "callback hell" syntax of libuv but It's harder than I imagined and not to mention I'll have to recreate most things from js ecosystem like (validators, http client, primitives for tcp/udp) for this to be anything remotely production ready and I just don't have the resources for that
A lightweight http server framework written in C3 powered by c3io and libuv, inspired by Hono, Elysia and express.js.
- Simple routing system with HTTP method support
- GET
- PUT
- POST
- HEAD
- TRACE
- PATCH
- DELETE
- CONNECT
- Content type handling (HTML, JSON, TXT, AAC, etc)
- Basic request/response handling
- Static file serving capability
- libuv Bindings (
uv) - C3 bindings for libuv API
- libuv - Cross-platform async I/O library
- C3 compiler - Version 0.6.x or later
Arch Linux:
sudo pacman -S libuvUbuntu/Debian:
sudo apt install libuv1-devmacOS:
brew install libuvFedora:
sudo dnf install libuv-develc3c testThe test suite includes 30 tests covering all async modules.
Add ceb as a submodule to your project:
git submodule add https://github.com/shishantbiswas/ceb.git lib/ceb.c3l
git submodule update --init --recursive
# for updating
# git submodule update --remote --recursiveThen add it to your project.json file like so:
// existing config
"dependency-search-paths": [
"lib"
],
"dependencies": [
"ceb" // emit the extension
]
// existing configmodule main;
import std::io;
import ceb;
fn int main() {
Server server;
server.init();
defer server.start();
server
.get("/heyo",
fn (
Request req
) => {
.status = 200,
.status_text = StatusText.OK,
.data = dstring::temp("Hello World"),
.content_type = ContentType.TXT
}
)
io::printf("Server starting...\n");
return 0;
}c3c buildThis will create build/main in the build directory.
Which is the server executable and can be deployed on most linux system and docker based platforms.
src- Source code files detailed belowlib- Lib files (contains c3io)test- Test filesdocs- Docs for usage of CEBbuild- Compiled outputscripts- Contains useful script to test the server like Apache bench
src/
├── ceb.c3
├── ceb_handlers.c3 // provider hono like interface like `server.get` and `server.use`
├── chunked.c3 // for chunked data used for streaming
├── enums.c3 // contains enums like (ContentType)
├── examples // examples directory
├── headers.c3 // internal parser util for header
├── middleware.c3 // contains middleware code
├── parser.c3 // code for header parser
├── router.c3 // tree based router similar to linear router from hono
├── utils.c3 // contains utilities, general purpose function
└── version.c3 // http versioning function- Early prototype stage
- Not optimized for production use
- Limited error handling
- No security features implemented
- Limited request parsing capabilities
- No SSL/TLS support
This project is in active development and should be considered alpha software. It is primarily intended for:
- Experimenting with web server concepts
- Understanding low-level networking
Do not use this in production environments.