Improve Middleware documentation and compile time static assertions #864
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #861
Currently there is some ambiguity in the documentation surrounding middlewares:
CROW_MIDDLEWARES
: In the reference docs the example usescrow::SimpleApp
, yet the example in Crow/examples states// ALL middleware (including per handler) is listed
and the guide doesn't mention this at all:It needs to be clarified, does
CROW_MIDDLEWARES
require the specified middleware be also specified in the referenced app template arguments?The reference docs mention the Crow constructor
Construct Crow with a subset of middleware.
, yet this is not explained in the Guide, and there's no example of the usage in the examples.The guide should include a section on configuring middlewares, which should include both with the constructor and with
app.get_middleware<>
.The examples should include an example on using the app constructor.
Also, we can reduce the confusion by implementing compile time static assertions:
CROW_MIDDLEWARES
, it should be validated that the type of that middleware is within the middlewares defined in the app class template types.TODO:
CROW_MIDDLEWARES
comment and example.app.get_middleware<>
.CROW_MIDDLEWARES
.As of writing, the PR includes an implementation that validates middlewares passed to the app constructor, however, the current implementation uses
std::decay
when comparing types. This needs to be discussed. It also needs more testing for edge cases IMO. Also, I'd like to do the same forCROW_MIDDLEWARES
but I don't know where to do so, a suggestion would be appreciated.