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 post method. #550

Merged
merged 3 commits into from
Oct 29, 2022
Merged

fix post method. #550

merged 3 commits into from
Oct 29, 2022

Conversation

lag945
Copy link
Contributor

@lag945 lag945 commented Oct 21, 2022

CROW_ROUTE(app, "/add_json") needs to specify post method, or it will return "405 Method Not Allowed".

@crow-clang-format
Copy link

--- examples/example_with_all.cpp	(before formatting)
+++ examples/example_with_all.cpp	(after formatting)
@@ -81,16 +81,15 @@
 
     // more json example
     CROW_ROUTE(app, "/add_json")
-	.methods("POST"_method)
-    ([](const crow::request& req) {
-        auto x = crow::json::load(req.body);
-        if (!x)
-            return crow::response(400);
-        int sum = x["a"].i() + x["b"].i();
-        std::ostringstream os;
-        os << sum;
-        return crow::response{os.str()};
-    });
+      .methods("POST"_method)([](const crow::request& req) {
+          auto x = crow::json::load(req.body);
+          if (!x)
+              return crow::response(400);
+          int sum = x["a"].i() + x["b"].i();
+          std::ostringstream os;
+          os << sum;
+          return crow::response{os.str()};
+      });
 
     CROW_ROUTE(app, "/params")
     ([](const crow::request& req) {

@lag945
Copy link
Contributor Author

lag945 commented Oct 21, 2022

I keep the same format with readme.md.

@mrozigor
Copy link
Member

Code will work, but according to RFC and common sense we should use POST. So you're right ;) Please fix code formatting accordingly with bot and I'll merge it.

@crow-clang-format
Copy link

--- examples/example_with_all.cpp	(before formatting)
+++ examples/example_with_all.cpp	(after formatting)
@@ -81,15 +81,15 @@
 
     // more json example
     CROW_ROUTE(app, "/add_json")
-	.methods("POST"_method)([](const crow::request& req) {
-        auto x = crow::json::load(req.body);
-        if (!x)
-            return crow::response(400);
-        int sum = x["a"].i() + x["b"].i();
-        std::ostringstream os;
-        os << sum;
-        return crow::response{os.str()};
-    });
+      .methods("POST"_method)([](const crow::request& req) {
+          auto x = crow::json::load(req.body);
+          if (!x)
+              return crow::response(400);
+          int sum = x["a"].i() + x["b"].i();
+          std::ostringstream os;
+          os << sum;
+          return crow::response{os.str()};
+      });
 
     CROW_ROUTE(app, "/params")
     ([](const crow::request& req) {

@lag945
Copy link
Contributor Author

lag945 commented Oct 27, 2022

@mrozigor Thanks for your advice. After 3 times commit, all checks have passed now :).

@mrozigor mrozigor merged commit e3ba10d into CrowCpp:master Oct 29, 2022
@lag945 lag945 deleted the examples_patch_20221021 branch October 29, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants