This feature is currently only available on the "master" branch.
Crow supports flask style blueprints.
A blueprint is a limited app. It cannot handle networking. But it can handle routes.
Blueprints allow developers to compartmentalize their Crow applications, making them a lot more modular.
In order for a blueprint to work, it has to be registered with a Crow app before the app is run. This can be done using
Blueprints let you do the following:
You can define routes in a blueprint, similarly to how
CROW_ROUTE(app, "/xyz") works, you can use
CROW_BP_ROUTE(blueprint, "/xyz") to define a blueprint route.
Define a Prefix
Blueprints can have a prefix assigned to them. This can be done when creating a new blueprint as in
crow::blueprint bp("prefix");. This prefix will be applied to all routes belonging to the blueprint. truning a route such as
Unlike routes, blueprint prefixes should contain no slashes.
Use a custom Static directory
Blueprints let you define a custom static directory (relative to your working directory). This can be done by initializing a blueprint as
crow::blueprint bp("prefix", "custom_static");. This does not have an effect on
set_static_file_info(), it's only for when you want direct access to a file.
Currently changing which endpoint the blueprint uses isn't possible, so whatever you've set in
CROW_STATIC_ENDPOINT (default is "static") will be used. Making your final route
Use a custom Templates directory
Similar to static directories, You can set a custom templates directory (relative to your working directory). To do this you initialize the blueprint as
crow::blueprint bp("prefix", "custom_static", "custom_templates");. Any routes defined for the blueprint will use that directory when calling
If you want to define a custom templates directory without defining a custom static directory, you can pass the static directory as an empty string. Making your constructor
crow::blueprint bp("prefix", "", "custom_templates");.
Define a custom Catchall route
You can define a custom catchall route for a blueprint by calling
CROW_BP_CATCHALL_ROUTE(blueprint). This causes any requests with a URL starting with
/prefix and no route found to call the blueprint's catchall route. if no catchall route is defined, Crow will default to either the parent blueprint or the app's catchall route.
Register other Blueprints
Blueprints can also register other blueprints. This is done through
blueprint.register_blueprint(blueprint_2);. The child blueprint's routes become