Overview
Discover what makes clink powerful
**clink** is a minimalistic, self‑hosted URL shortener written entirely in C and powered by the embedded web server library **Mongoose**. The project deliberately eschews heavyweight frameworks, offering a single‑binary deployment that can be compiled on any POSIX system. Its core functionality is to accept a long URL via an HTTP endpoint, generate a short identifier, store the mapping in memory or a lightweight file‑based database, and redirect clients to the original address. The API surface is intentionally small: a POST endpoint for creation, a GET endpoint for redirection, and optional query parameters to customize expiration or custom aliases.
Pure C implementation
In‑memory + optional persistence
HTTPS support
Rate limiting & basic auth
Overview
clink is a minimalistic, self‑hosted URL shortener written entirely in C and powered by the embedded web server library Mongoose. The project deliberately eschews heavyweight frameworks, offering a single‑binary deployment that can be compiled on any POSIX system. Its core functionality is to accept a long URL via an HTTP endpoint, generate a short identifier, store the mapping in memory or a lightweight file‑based database, and redirect clients to the original address. The API surface is intentionally small: a POST endpoint for creation, a GET endpoint for redirection, and optional query parameters to customize expiration or custom aliases.
Key Features
- Pure C implementation – no external dependencies beyond the standard library and Mongoose, enabling static linking and easy cross‑compilation.
- In‑memory + optional persistence – URL mappings are held in a hash table; the state can be dumped to a JSON file for recovery.
- HTTPS support – Mongoose handles TLS via OpenSSL; self‑signed certificates are auto‑generated if not provided.
- Rate limiting & basic auth – configurable via command line flags or a simple config file, useful for protecting the creation endpoint.
- Webhooks – optional POST callbacks on link creation or deletion, allowing integration with CI/CD pipelines or analytics services.
Technical Stack
| Layer | Technology |
|---|---|
| Runtime | C99 (GNU C compiler) |
| Web Server | Mongoose 6.x (embedded HTTP/HTTPS server) |
| Storage | Custom hash table; optional JSON persistence |
| Build System | Makefile (supports make install, systemd unit generation, Docker target) |
| Containerization | Dockerfile included; builds a minimal Alpine‑based image |
The codebase is split into three logical modules:
main.c – entry point, argument parsing, and server initialization.
mongoose.c/h – thin wrapper around Mongoose to expose request handlers.
clinkctl/ – a small CLI tool for managing links (list, delete, stats) and for generating self‑signed certs.
Architecture
- Request Handling – Mongoose listens on a configurable port; each incoming request is dispatched to
handle_request(). - URL Mapping – A thread‑safe hash table (
url_map) storesshort_id → long_urlpairs. The key is a base‑62 encoded counter or a user‑supplied slug. - Persistence Layer – On startup, the binary reads
clink.db(JSON) into memory; on shutdown or every N seconds, it writes back to disk. - CLI Control –
clinkctlcommunicates with the running instance via Unix domain sockets, allowing administrative commands without exposing a separate HTTP API.
Deployment & Infrastructure
- Self‑hosting – A single static binary (
clink) can be dropped onto any Linux/Unix host. No runtime dependencies other than libc and OpenSSL. - Scalability – While the single‑process model limits concurrency to a few hundred concurrent connections, it is sufficient for low‑to‑medium traffic. For higher load, deploy behind a reverse proxy (NGINX/Traefik) with sticky sessions or run multiple instances behind a load balancer.
- Containerization – The included Dockerfile builds an Alpine image; the container can be orchestrated with Docker Compose, Kubernetes (Deployment + Service), or any other container platform.
- Infrastructure as Code – The Makefile can generate a
systemdunit file (clink.service) and an NGINX configuration snippet, simplifying production deployments.
Integration & Extensibility
- API – The minimal REST API (
POST /shorten,GET /{id}) can be consumed by any language. - Webhooks – Developers can register a callback URL; clink POSTs JSON payloads containing the new short link data.
- Plugins – While no plugin system exists, the modular C code allows developers to fork and extend
mongoose.cfor custom authentication, analytics, or storage backends (e.g., SQLite). - CLI –
clinkctlexposes commands for bulk import/export, statistics, and manual cleanup, which can be scripted in CI pipelines.
Developer Experience
- Configuration – Options are passed via command line flags (
--port,--cert,--key) or a simple TOML file (clink.conf). - Documentation – The README provides an overview, build instructions, and API reference. Inline comments in the source are concise but sufficient for understanding the flow.
- Community & Support – The project has a modest issue tracker; contributors are welcomed. Licensing is MIT, allowing unrestricted use in commercial or proprietary projects.
Use Cases
- Internal tooling – Shorten URLs for internal dashboards, logs, or documentation links within a corporate network.
- API gateway – Expose a clean endpoint for external services while keeping the original URLs hidden.
- Rapid prototyping – Developers can spin up a shortener in seconds to test URL routing or analytics pipelines.
- Self‑hosted social platforms – Integrate with custom CMSs to generate shareable links without relying on third‑party services.
Advantages Over Alternatives
| Criterion | clink |
|---|---|
| Performance | Single‑threaded C + Mongoose; low memory footprint (~10 MB). |
| Simplicity | No ORM, no database server; a |
Open SourceReady to get started?
Join the community and start self-hosting clink today
Related Apps in apis-services
Mastodon
Decentralized, real‑time social networking
Discourse
Open‑source community forum platform with real‑time chat and AI
Rocket.Chat
Secure, open‑source team communication platform
Novu
Unified notification platform for multi‑channel delivery
Mattermost
Secure, self‑hosted team collaboration with chat, voice, and AI
Jitsi Meet
Free, encrypted video conferencing for everyone
Weekly Views
Repository Health
Information
Explore More Apps

CMS Made Simple
Simple, flexible CMS for editors, designers and developers
Accent
Developer‑oriented translation tool for seamless collaboration
Ocular
Visualize and manage budgets with a self-hosted dashboard
Thelia
Customizable, French‑made e‑commerce platform for scalable online stores
BookStack
Self‑hosted wiki for easy knowledge organization
Open QuarterMaster
All‑in‑one inventory system for every scale