A Fast and Easy to use microframework for the web.
Go to file
2020-10-31 20:04:14 +03:00
cmake tcmalloc linking added 2014-08-14 19:22:02 -04:00
examples Merge branch 'master' into multipart 2020-10-20 10:10:52 +03:00
include documented most of app.h 2020-10-22 04:13:57 +03:00
scripts moved all scripts to a single folder 2020-10-31 20:03:47 +03:00
tests Merge branch 'master' into stream_body 2020-10-21 19:50:01 +03:00
.clang-format CMakeLists small changes. Add clang-format config. Remove Makefile. 2020-10-19 18:32:16 +02:00
.gitignore added QT Creator project files to .gitignore 2020-10-31 20:04:14 +03:00
.gitmodules Removed http-parser submodule 2014-10-15 18:20:48 +01:00
.travis.yml moved all scripts to a single folder 2020-10-31 20:03:47 +03:00
CMakeLists.txt Remove conanfile. Update mustache specification jsons. Remove compilation warnings. Update CMake version. Change test framework to Catch2. 2020-10-19 18:32:16 +02:00
Doxyfile Merge branch 'master' into covverage-exclude-3rdparty 2020-10-19 11:33:48 +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 fixed typo 2020-10-20 16:23:09 +03:00

Crow logo

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

Travis Build Coverage Status Gitter

#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
  • All-in-one header file available
  • 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, generate crow_all.h (use script amalgamate/merge_all.py) and include it.

Requirements

  • C++ compiler with good C++14 support.
    • Tested on g++-9.3 and clang-7.0, AMD64 (x86_64) and Arm64 v8
  • boost 1.7 library.
  • (optional) CMake to build tests and/or examples.
  • (optional) Linking with tcmalloc/jemalloc is recommended for speed.

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.