C++14 的 Web 框架:Silicon

jopen 9年前

Silicon 是一个高性能的面向中间件的 C++14 HTTP Web 开发框架,为 C++ 带来类似其他基于动态语言 Web 框架的便利性。

Features

  • Ease of use:

    The framework is designed such that the developper only writes the core of the API, the framework takes care of the rest (serialization, deserialization, generation of client libraries, routing, multithreading, ...)

  • Fast:

    C++ has no overhead such as other web programming languages: No interpreter, no garbage collection, no virtual machine and no just in time compiler. It provides several http server backend: microhttpd, mimosa and cpp-netlib.

  • Verified:

    Thanks to the static programming paradigm of the framework, lots of the common errors will be detected and reported by the compiler.

  • Automatic dependency injection and middlewares:

    Middlewares are objects requests by the api. They can be access to a session, connection to a database or another webservice, or anything else that need to be initialized before each api call. Middlewares may depend on each other, leading to a middleware dependency graph automatically resolved at compile time.

  • Automatic validation, serialization and deserialization of messages:

    Relying on static introspection on api arguments and return types, a pair fast parser and encoder is generated for each message type. The request do not reach the api until it contains all the required arguments.

  • Automatic generation of the client libraries:

    Because the framework knows the input and output type of each api procedure, it is able to automatically generate the code of the remote client. The C++ client is generated at compile time and other languages are generated at runtime thanks to a tiny templating engine.

  • Not dependent on the underlying network library or serialization format:

    The core code of an API is not tied to a specific network library or serialization format. The first version of silicon provides simple http backends: microhttpd, mimosa and cpp-netlib, and the json format. However, in the future the library could support websocket, binary protocols, ...


Hello World

Here is a simple hello world example serving the string {"message":"hello world."} at the route /hello.

#include <silicon/api.hh>  #include <silicon/mhd_serve.hh>    using namespace sl;    // Define the API:  auto hello_api = make_api(      // The hello world procedure.    @hello = [] () { return D(@message = "Hello world."); }    );    int main()  {    // Serve hello_api via microhttpd using the json format:    sl::mhd_json_serve(hello_api, 12345);  }


项目主页:http://www.open-open.com/lib/view/home/1421723777203