A Modern, Fast, and Lightweight REST API Framework for C/C++
π Documentation β’ π Quick Start β’ π€ Contributing
A production-ready, high-performance RESTful API framework for C and C++. Inspired by modern API frameworks for simplicity and developer experience.
Crest is Still in Early Development. Expect frequent changes and updates.
- π High Performance - Built for speed with minimal overhead and thread pool
- π§ C & C++ Support - Use with both C and C++ projects
- π Auto Documentation - Built-in Swagger UI at
/docs - π― Simple API - Intuitive, easy-to-use interface
- π Production Ready - Exception handling, validation, and error reporting
- π Cross-Platform - Windows, Linux, and macOS support
- π¦ Easy Integration - Install via xmake, Conan, or vcpkg
- β‘ Modern C++20 - Leverages latest C++ features
- π¨ Responsive UI - Beautiful, mobile-friendly documentation interface
- π Middleware System - CORS, rate limiting, authentication, logging
- π WebSocket Support - Real-time bidirectional communication
- πΎ Database Helpers - Connection pooling, query builder, ORM-like models
- π File Upload - Multipart form data parsing with validation
- π¨ Template Engine - Dynamic HTML rendering with filters and conditionals
xmake repo -u
xmake require crestIn your xmake.lua:
add_requires("crest")
target("your_app")
set_kind("binary")
add_packages("crest")
add_files("src/*.cpp")git clone https://github.com/muhammad-fiaz/crest.git
cd crest
xmake build
xmake installDownload the latest packages from GitHub Releases - includes binaries, xmake, Conan, and vcpkg packages.
#include "crest/crest.hpp"
int main() {
crest::App app;
app.get("/", [](crest::Request& req, crest::Response& res) {
res.json(200, R"({"message":"Hello, World!"})");
});
app.run("0.0.0.0", 8000);
return 0;
}#include "crest/crest.h"
void handle_root(crest_request_t* req, crest_response_t* res) {
crest_response_json(res, 200, "{\"message\":\"Hello, World!\"}");
}
int main(void) {
crest_app_t* app = crest_create();
crest_route(app, CREST_GET, "/", handle_root, "Root endpoint");
crest_run(app, "0.0.0.0", 8000);
crest_destroy(app);
return 0;
}Full documentation is available at: https://muhammad-fiaz.github.io/Crest
- C API Documentation
- C++ API Documentation
- Configuration Guide
- Logging System
- Performance & Concurrency
- HTTP Status Codes Guide
- Schema Documentation
- Middleware System
- WebSocket Support
- Database Integration
- File Upload Handling
- Template Engine
- Examples
Define routes with HTTP methods:
app.get("/users", handler); // GET request
app.post("/users", handler); // POST request
app.put("/users/:id", handler); // PUT request
app.del("/users/:id", handler); // DELETE request
app.patch("/users/:id", handler); // PATCH requestapp.get("/api/data", [](crest::Request& req, crest::Response& res) {
std::string body = req.body();
std::string query = req.query("param");
std::string header = req.header("Authorization");
res.json(200, R"({"status":"success"})");
});res.json(200, R"({"key":"value"})"); // JSON response
res.text(200, "Plain text"); // Text response
res.html(200, "<h1>HTML</h1>"); // HTML response// Set schemas to match your actual responses
app.set_response_schema(crest::Method::GET, "/user",
R"({"id": "number", "name": "string", "email": "string"})");
app.set_request_schema(crest::Method::POST, "/user",
R"({"name": "string", "email": "string"})");crest::Config config;
config.title = "My API";
config.description = "API Description";
config.version = "1.0.0";
config.docs_enabled = true;
config.docs_path = "/docs";
config.openapi_path = "/openapi.json";
crest::App app(config);app.set_proxy("http://proxy.example.com:8080");app.run("127.0.0.1", 3000);app.set_docs_enabled(false);try {
app.run("0.0.0.0", 8000);
} catch (const crest::Exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}Crest automatically generates interactive API documentation accessible at /docs:
- Responsive Design - Works on all devices
- Real-time Updates - Reflects all registered routes
- OpenAPI Spec - Available at
/openapi.json - Error Display - Shows route conflicts and errors
crest/
βββ include/
β βββ crest/
β βββ crest.h # C API
β βββ crest.hpp # C++ API
β βββ internal/ # Internal headers
βββ src/
β βββ core/ # Core functionality
β βββ http/ # HTTP handling
β βββ router/ # Route management
β βββ server/ # Server implementation
β βββ middleware/ # Middleware support
β βββ swagger/ # Documentation generation
β βββ utils/ # Utilities
βββ examples/
β βββ c/ # C examples
β βββ cpp/ # C++ examples
βββ tests/ # Test suite
βββ docs/ # Documentation
βββ xmake.lua # Build configuration
Run the test suite:
xmake build crest_tests
xmake run crest_testsContributions are welcome! Please read our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
Muhammad Fiaz
- Email: contact@muhammadfiaz.com
- GitHub: @muhammad-fiaz
Crest is inspired by modern API frameworks that prioritize simplicity and developer experience.
Found a bug? Please open an issue on GitHub.