A Fast and Easy to use microframework for the web.
Go to file
The-EDev 661a03c3da Updated doxygen
changed to dark theme (darkxygen)
added version, logo, and STL consideration
excluded third party libraries
2020-10-17 23:53:25 +03:00
amalgamate Changed path to env application. 2019-11-05 20:58:50 +01:00
cmake tcmalloc linking added 2014-08-14 19:22:02 -04:00
examples added static file example 2020-10-04 19:29:56 +03:00
include Removed unnecessary variables 2020-10-15 13:59:15 +03:00
scripts Added variable input output paths as arguments to mime type generator 2020-10-13 01:01:47 +03:00
tests added test for 405 code on wrong method 2020-10-15 01:24:26 +03:00
.gitignore #7 Change Doxyfile - it should generate standard html files by default. 2020-10-14 20:09:44 +02:00
.gitmodules Removed http-parser submodule 2014-10-15 18:20:48 +01:00
.travis.yml Updated doxygen 2020-10-17 23:53:25 +03:00
CMakeLists.txt Fixed CMakeLists - merge_all.py script takes output path. 2020-07-10 22:47:51 +02:00
conanfile.py #7 Change Doxyfile - it should generate standard html files by default. 2020-10-14 20:09:44 +02:00
Doxyfile Updated doxygen 2020-10-17 23:53:25 +03:00
generateDocumentationAndDeploy.sh Updated doxygen 2020-10-17 23:53:25 +03:00
LICENSE Update LICENSE 2014-04-20 03:55:41 +09:00
logo55.png Updated doxygen 2020-10-17 23:53:25 +03:00
README.md updated versions in readme 2020-10-14 15:02:13 +03:00

Crow logo

Crow is C++ microframework for web. (inspired by Python Flask)

Travis Build Coverage Status

#include "crow.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });

    app.port(18080).multithreaded().run();
}

Features

  • Easy routing
    • Similiar to Flask
    • Type-safe Handlers (see Example)
  • Very Fast
  • Fast built-in JSON parser (crow::json)
  • Mustache based templating library (crow::mustache)
  • Header only
  • Provide an amalgamated header file crow_all.h with every features (Download from here)
  • Middleware support
  • Websocket support

Still in development

  • Built-in ORM

Examples

JSON Response

CROW_ROUTE(app, "/json")
([]{
    crow::json::wvalue x;
    x["message"] = "Hello, World!";
    return x;
});

Arguments

CROW_ROUTE(app,"/hello/<int>")
([](int count){
    if (count > 100)
        return crow::response(400);
    std::ostringstream os;
    os << count << " bottles of beer!";
    return crow::response(os.str());
});

Handler arguments type check at compile time

// Compile error with message "Handler type is mismatched with URL paramters"
CROW_ROUTE(app,"/another/<int>")
([](int a, int b){
    return crow::response(500);
});

Handling JSON Requests

CROW_ROUTE(app, "/add_json")
.methods("POST"_method)
([](const crow::request& req){
    auto x = crow::json::load(req.body);
    if (!x)
        return crow::response(400);
    int sum = x["a"].i()+x["b"].i();
    std::ostringstream os;
    os << sum;
    return crow::response{os.str()};
});

How to Build

If you just want to use crow, copy amalgamate/crow_all.h and include it.

Requirements

  • C++ compiler with good C++11 support (tested with g++>=8).

  • boost 1.7 library.

  • (optional) CMake to build tests and/or examples.

  • (optional) Linking with tcmalloc/jemalloc is recommended for speed.

  • Now supporting VS2013 with limited functionality (only run-time check for url is available.)

Building (Tests, Examples)

Out-of-source build with CMake is recommended.

mkdir build
cd build
cmake ..
make

You can run tests with following commands:

ctest

Installing missing dependencies

Ubuntu

sudo apt-get install build-essential libtcmalloc-minimal4 && sudo ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so

OSX

brew install boost google-perftools

Attributions

Crow uses the following libraries.

http-parser

https://github.com/nodejs/http-parser

http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
Igor Sysoev.

Additional changes are licensed under the same terms as NGINX and
copyright Joyent, Inc. and other Node contributors. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE. 


qs_parse

https://github.com/bartgrantham/qs_parse

Copyright (c) 2010 Bart Grantham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.


TinySHA1

https://github.com/mohaps/TinySHA1

TinySHA1 - a header only implementation of the SHA1 algorithm. Based on the implementation in boost::uuid::details

Copyright (c) 2012-22 SAURAV MOHAPATRA mohaps@gmail.com
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.