Skip to content

Crest is a production-ready REST API framework for C and C++ that combines the simplicity of modern web frameworks with the performance of native code. Build fast, type-safe HTTP APIs with minimal boilerplate.

License

Notifications You must be signed in to change notification settings

muhammad-fiaz/Crest

Repository files navigation

Logo

A Modern, Fast, and Lightweight REST API Framework for C/C++

Version License Last Commit Issues Pull Requests Platform

πŸ“š 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.

✨ Features

  • πŸš€ 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

πŸ“¦ Installation

Using xmake (Recommended)

xmake repo -u
xmake require crest

In your xmake.lua:

add_requires("crest")

target("your_app")
    set_kind("binary")
    add_packages("crest")
    add_files("src/*.cpp")

Build from Source

git clone https://github.com/muhammad-fiaz/crest.git
cd crest
xmake build
xmake install

Download Pre-built Binaries

Download the latest packages from GitHub Releases - includes binaries, xmake, Conan, and vcpkg packages.

πŸš€ Quick Start

C++ Example

#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;
}

C Example

#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;
}

πŸ“– Documentation

Full documentation is available at: https://muhammad-fiaz.github.io/Crest

🎯 Core Concepts

Routes

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 request

Request Handling

app.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"})");
});

Response Types

res.json(200, R"({"key":"value"})");        // JSON response
res.text(200, "Plain text");                 // Text response
res.html(200, "<h1>HTML</h1>");             // HTML response

Schema Definition

// 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"})");

Configuration

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);

πŸ”§ Advanced Features

Proxy Configuration

app.set_proxy("http://proxy.example.com:8080");

Custom Host and Port

app.run("127.0.0.1", 3000);

Disable Documentation in Production

app.set_docs_enabled(false);

Exception Handling

try {
    app.run("0.0.0.0", 8000);
} catch (const crest::Exception& e) {
    std::cerr << "Error: " << e.what() << std::endl;
}

πŸ“Š Swagger UI

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

πŸ—οΈ Project Structure

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

πŸ§ͺ Testing

Run the test suite:

xmake build crest_tests
xmake run crest_tests

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘€ Author

Muhammad Fiaz

πŸ™ Acknowledgments

Crest is inspired by modern API frameworks that prioritize simplicity and developer experience.

πŸ› Bug Reports

Found a bug? Please open an issue on GitHub.


Star History Chart

⭐ Star the repository if you find Crest useful!

About

Crest is a production-ready REST API framework for C and C++ that combines the simplicity of modern web frameworks with the performance of native code. Build fast, type-safe HTTP APIs with minimal boilerplate.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published