1

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);
    }
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
yamilyana
  • 11
  • 4

1 Answers1

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).

Samichoulo
  • 46
  • 4