'Api server rest with crow
I am implementing a server rest using Crow. In my code i want to do some action before sending the response. These action are complimented in another class. it is possible to call this method in the Crow_Route? I need something like :
CROW_ROUTE(app, "/api/rest/v1/image")
.methods("GET"_method)
([](const request& req ) {
if (req.method == "GET"_method)
{
manager->manageRequestImage();
}
else
{
return response(401);
}
Solution 1:[1]
you should be able to do so by simply capturing your manager in your callback.
CROW_ROUTE(app, "/api/rest/v1/image")
.methods("GET"_method)(
[&manager](const request& req ) {
if (req.method == "GET"_method)
{
manager->manageRequestImage();
return response(200);
}
else
{
return response(401);
}
});
I don't think you need the if statement since you already specify that its a "GET" endpoint with .methods("GET"_method).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Samichoulo |