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

Documentation / Post example #288

Open
marosiak opened this issue Feb 22, 2018 · 1 comment
Open

Documentation / Post example #288

marosiak opened this issue Feb 22, 2018 · 1 comment

Comments

@marosiak
Copy link

Hey, could I get full documentation or post example? I want to recive Post's like
http:/example.com/login/?username=tester&password=myPassword
But I don't understand the only example which I've found in readme.md

Or mayby any idea how url would looks like for this:

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()};
});
@netromdk
Copy link

netromdk commented Feb 22, 2018

In this case the request (HTTP) body is expected to be JSON data.

Example

{"a": 1, "b": 2}

If you want query values, you have to access crow::request::url_params (crow/http_request.h:29) on which these are some of the ways you can interact with it (from crow/query_string.h):

char* query_string::get(const std::string& name) const;
std::vector<char*> query_string::get_list(const std::string& name) const;
std::unordered_map<std::string, std::string> query_string::get_dict(const std::string& name) const;

In particular, if you wanted to get "username" and "password":

const auto username = req.url_params.get("username");
const auto password = req.url_params.get("password");

I hope that helps. Feel free to look through the code, it helps a lot to understand how to use it.

GerHobbelt pushed a commit to GerHobbelt/crow that referenced this issue Nov 29, 2021
Enable a better experience using custom loggers.
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

No branches or pull requests

2 participants