A lightweight http server framework written in C3 powered by c3io and libuv, inspired by Hono, Elysia and express.js .
Features
- 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
Low-Level Bindings
- libuv Bindings (
uv) - C3 bindings for libuv API
Dependencies
- libuv - Cross-platform async I/O library
- C3 compiler - Version 0.6.x or later
Installing libuv
Arch Linux:
sudo pacman -S libuv
Ubuntu/Debian:
sudo apt install libuv1-dev
macOS:
brew install libuv
Fedora:
sudo dnf install libuv-devel
Testing
c3c test
The test suite includes 30 tests covering all async modules.
Usage
As a Git Submodule
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 --recursive
Then add it to your project.json file like so:
// existing config
"dependency-search-paths": [
"lib"
],
"dependencies": [
"ceb" // emit the extension
]
// existing config
Minimal Example
module 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;
}
Building
c3c build
This 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.
Project Structure
src- Source code files detailed belowbuild- Compiled outputdocs- Docs for usage of CEBtest- Test fileslib- Lib files (contains c3io)scripts- 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
Current Limitations
- Early prototype stage
- Not optimized for production use
- Limited error handling
- No security features implemented
- Limited request parsing capabilities
- No SSL/TLS support
Development Status
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.