Included middlewares

Crow ships a handful of ready-made middlewares; Garvan exposes all of them. Pull in whichever you need and add it as a template parameter to crow::App.

CORS handler

#include "crow/middlewares/cors.h"

crow::App<crow::CORSHandler> app;
auto &cors = app.get_middleware<crow::CORSHandler>();
cors.global().origin("https://example.com").allow_credentials();
#include "crow/middlewares/cookie_parser.h"

crow::App<crow::CookieParser> app;

CROW_ROUTE(app, "/whoami")([&](const crow::request &req) {
    auto &cookies = app.get_context<crow::CookieParser>(req);
    return cookies.get_cookie("session");
});

Session middleware

The session middleware is built on top of the cookie parser and stores arbitrary key/value data on the server side.

#include "crow/middlewares/session.h"

crow::App<crow::CookieParser, crow::SessionMiddleware<crow::InMemoryStore>> app{
    crow::SessionMiddleware<crow::InMemoryStore>{}
};