Documentation
libchttpx is a compact HTTP/2 server library for C. This page covers installation and the first server. Module details live in the sidebar.
Installation
For Debian and Ubuntu on amd64, add the libchttpx APT repository once and install the development package.
curl -fsSL https://netcorelink.github.io/libchttpx/apt/libchttpx.sources \
| sudo tee /etc/apt/sources.list.d/libchttpx.sources >/dev/null
sudo apt update
sudo apt install libchttpx-dev
After that, future versions are installed through the normal APT update flow:
sudo apt update
sudo apt upgrade
To remove libchttpx:
sudo apt remove libchttpx-dev
The APT repository currently targets Debian/Ubuntu on amd64 and uses Trusted: yes, so there is no separate GPG-key setup. Package signing can be added later.
Build from source
If you do not want to use the APT repository, the existing source installation remains available.
sudo apt update
sudo apt install -y build-essential pkg-config libcjson-dev zlib1g-dev
git clone https://github.com/netcorelink/libchttpx.git
cd libchttpx
make lin-lib
sudo make lib-install PREFIX=/usr/local DESTDIR=
First server
Create an app, configure a server, add a route, then run the app.
#include <libchttpx.h>
static void health(chttpx_request_t* req, chttpx_response_t* res)
{
(void)req;
*res = cHTTPX_ResMessage(cHTTPX_StatusOK, "healthy");
}
int main(void)
{
chttpx_app_t app;
if (cHTTPX_AppInit(&app) != cHTTPX_OK)
return 1;
chttpx_config_t config = cHTTPX_DefaultConfig();
config.port = 8080;
chttpx_serv_t* server = cHTTPX_AppServer(&app, "main", &config);
chttpx_router_t router = cHTTPX_RoutePathPrefix(server, "");
cHTTPX_Get(&router, "/health", health);
int result = cHTTPX_AppRun(&app);
cHTTPX_AppShutdown(&app);
return result == cHTTPX_OK ? 0 : 1;
}
Compile
After installation, use pkg-config to get include and linker flags.
gcc server.c -o server $(pkg-config --cflags --libs libchttpx)
./server
Modules
Filter the list and open the full module documentation.