Crow  1.1
A C++ microframework for the web
app.h File Reference

This file includes the definition of the crow::Crow class, the crow::App and crow::SimpleApp aliases, and some macros. More...

#include <chrono>
#include <string>
#include <functional>
#include <memory>
#include <future>
#include <cstdint>
#include <type_traits>
#include <thread>
#include <condition_variable>
#include "crow/version.h"
#include "crow/settings.h"
#include "crow/logging.h"
#include "crow/utility.h"
#include "crow/routing.h"
#include "crow/middleware_context.h"
#include "crow/http_request.h"
#include "crow/http_server.h"
#include "crow/task_timer.h"
#include "crow/websocket.h"
#include "crow/compression.h"

Go to the source code of this file.

Classes

class  crow::Crow< Middlewares >
 The main server application class. More...
 

Namespaces

 crow
 The main namespace of the library. In this namespace is defined the most important classes and functions of the library.
 

Macros

#define CROW_ROUTE(app, url)   app.template route<crow::black_magic::get_parameter_tag(url)>(url)
 Creates a route for app using a rule. More...
 
#define CROW_BP_ROUTE(blueprint, url)   blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)
 Creates a route for a blueprint using a rule. More...
 
#define CROW_WEBSOCKET_ROUTE(app, url)   app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)
 Defines WebSocket route for app. More...
 
#define CROW_MIDDLEWARES(app, ...)   template middlewares<typename std::remove_reference<decltype(app)>::type, __VA_ARGS__>()
 Enable a Middleware for an specific route in app or blueprint. More...
 
#define CROW_CATCHALL_ROUTE(app)   app.catchall_route()
 Defines a custom catchall route for app using a custom rule. More...
 
#define CROW_BP_CATCHALL_ROUTE(blueprint)   blueprint.catchall_rule()
 Defines a custom catchall route for blueprint using a custom rule. More...
 

Typedefs

using crow::ssl_context_t = asio::ssl::context
 
template<typename... Middlewares>
using crow::App = Crow< Middlewares... >
 Alias of Crow<Middlewares...>. Useful if you want a instance of an Crow application that require Middlewares.
 
using crow::SimpleApp = Crow<>
 Alias of Crow<>. Useful if you want a instance of an Crow application that doesn't require of Middlewares.
 

Detailed Description

This file includes the definition of the crow::Crow class, the crow::App and crow::SimpleApp aliases, and some macros.

In this file are defined:

Macro Definition Documentation

◆ CROW_BP_CATCHALL_ROUTE

#define CROW_BP_CATCHALL_ROUTE (   blueprint)    blueprint.catchall_rule()

Defines a custom catchall route for blueprint using a custom rule.

It defines a handler when the client make a request for an undefined route in the blueprint.

See also
Page of the guide "Blueprint" (Define a custom Catchall route).

◆ CROW_BP_ROUTE

#define CROW_BP_ROUTE (   blueprint,
  url 
)    blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)

Creates a route for a blueprint using a rule.

It may use crow::Blueprint::new_rule_dynamic or crow::Blueprint::new_rule_tagged to define a new rule for an given blueprint. It's usage is similar to CROW_ROUTE macro:

CROW_BP_ROUTE(my_bp, "/")
([](){
return "<h1>Hello, world!</h1>";
});
#define CROW_BP_ROUTE(blueprint, url)
Creates a route for a blueprint using a rule.
Definition: app.h:94
A blueprint can be considered a smaller section of a Crow app, specifically where the router is conec...
Definition: routing.h:1104

This is the recommended way to define routes in a crow blueprint because of its compile-time capabilities.

See also
Page of the guide "Blueprints".

◆ CROW_CATCHALL_ROUTE

#define CROW_CATCHALL_ROUTE (   app)    app.catchall_route()

Defines a custom catchall route for app using a custom rule.

It defines a handler when the client make a request for an undefined route. Instead of just reply with a 404 status code (default behavior), you can define a custom handler using this macro.

See also
Page of the guide "Routes" (Catchall routes).

◆ CROW_MIDDLEWARES

#define CROW_MIDDLEWARES (   app,
  ... 
)    template middlewares<typename std::remove_reference<decltype(app)>::type, __VA_ARGS__>()

Enable a Middleware for an specific route in app or blueprint.

It defines the usage of a Middleware in one route. And it can be used in both crow::SimpleApp (and crow::App) instances and crow::Blueprint. Its usage syntax is like this:

auto app = crow::SimpleApp(); // or crow::App()
CROW_ROUTE(app, "/with_middleware")
.CROW_MIDDLEWARES(app, LocalMiddleware) // Can be used more than one
([]() { // middleware.
return "Hello world!";
});
#define CROW_ROUTE(app, url)
Creates a route for app using a rule.
Definition: app.h:70
Crow<> SimpleApp
Alias of Crow<>. Useful if you want a instance of an Crow application that doesn't require of Middlew...
Definition: app.h:775
See also
Page of the guide "Middlewares".

◆ CROW_ROUTE

#define CROW_ROUTE (   app,
  url 
)    app.template route<crow::black_magic::get_parameter_tag(url)>(url)

Creates a route for app using a rule.

It use crow::Crow::route_dynamic or crow::Crow::route to define a rule for your application. It's usage is like this:

auto app = crow::SimpleApp(); // or crow::App()
CROW_ROUTE(app, "/")
([](){
return "<h1>Hello, world!</h1>";
});

This is the recommended way to define routes in a crow application.

See also
Page of guide "Routes".

◆ CROW_WEBSOCKET_ROUTE

#define CROW_WEBSOCKET_ROUTE (   app,
  url 
)    app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)

Defines WebSocket route for app.

It binds a WebSocket route to app. Easy solution to implement WebSockets in your app. The usage syntax of this macro is like this:

auto app = crow::SimpleApp(); // or crow::App()
.onopen([&](crow::websocket::connection& conn){
do_something();
})
.onclose([&](crow::websocket::connection& conn, const std::string& reason){
do_something();
})
.onmessage([&](crow::websocket::connection&, const std::string& data, bool is_binary){
if (is_binary)
do_something(data);
else
do_something_else(data);
});
#define CROW_WEBSOCKET_ROUTE(app, url)
Defines WebSocket route for app.
Definition: app.h:123
A base class for websocket connection.
Definition: websocket.h:38
See also
Page of the guide "WebSockets".