Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indentation & numbering in middleware #378

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 23 additions & 21 deletions docs/guides/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,39 @@ There are two possible signatures for before_handle

1. if you only need to access this middleware's context.

```cpp
void before_handle(request& req, response& res, context& ctx)
```
```cpp
void before_handle(request& req, response& res, context& ctx)
```

2. To get access to other middlewares context
``` cpp
template <typename AllContext>
void before_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
{
auto other_ctx = all_ctx.template get<OtherMiddleware>();
}
```

``` cpp
template <typename AllContext>
void before_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
{
auto other_ctx = all_ctx.template get<OtherMiddleware>();
}
```


## after_handle
There are two possible signatures for after_handle

1. if you only need to access this middleware's context.

```cpp
void after_handle(request& req, response& res, context& ctx)
```
```cpp
void after_handle(request& req, response& res, context& ctx)
```

2. To get access to other middlewares context
``` cpp
template <typename AllContext>
void after_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
{
auto other_ctx = all_ctx.template get<OtherMiddleware>();
}
```

``` cpp
template <typename AllContext>
void after_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
{
auto other_ctx = all_ctx.template get<OtherMiddleware>();
}
```

## Using middleware

Expand Down Expand Up @@ -91,4 +93,4 @@ struct AdminAreaGuard : crow::ILocalMiddleware
void after_handle(crow::request& req, crow::response& res, context& ctx)
{}
};
```
```